“THROW"附近的语法不正确 [英] Incorrect syntax near 'THROW'
本文介绍了“THROW"附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IF @SQL IS NOT NULL
BEGIN
BEGIN TRY
EXEC sp_executesql @SQL
PRINT 'SUCCESS: ' + @SQL
END TRY
BEGIN CATCH
SET @ErrorMessage =
N'Error dropping constraint' + @CRLF
+ 'Table ' + @TableName + @CRLF
+ 'Script: ' + @SQL + @CRLF
+ 'Error message: ' + ERROR_MESSAGE() + @CRLF
THROW 50100, @ErrorMessage, 1;
END CATCH
END
当 CATCH
执行时,我收到以下错误:
When the CATCH
executes, I get the following error:
消息 102,级别 15,状态 1,第 257 行
THROW"附近的语法不正确.
Msg 102, Level 15, State 1, Line 257
Incorrect syntax near 'THROW'.
用 PRINT @ErrorMessage
替换 THROW
有效.
用文字字符串替换 @ErrorMessage
变量有效.
Replacing @ErrorMessage
variable with a literal string works.
然而,根据文档,THROW 应该能够接受一个变量.不知道该怎么做.
According to the docs, however, THROW is supposed to be able to take a variable. Not sure what to make of this.
推荐答案
来自 MSDN:
THROW 语句之前的语句后面必须跟有分号 (;) 语句终止符.
The statement before the THROW statement must be followed by the semicolon (;) statement terminator.
这篇关于“THROW"附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文