gpt4 book ai didi

sql-server - 'THROW' 附近的语法不正确

转载 作者:行者123 更新时间:2023-12-01 23:25:23 28 4
gpt4 key购买 nike

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执行时,我收到以下错误:

Msg 102, Level 15, State 1, Line 257
Incorrect syntax near 'THROW'.

PRINT @ErrorMessage 替换 THROW 是可行的。

用文字字符串替换 @ErrorMessage 变量是可行的。

但是,根据文档,THROW 应该能够接受变量。不知道该怎么做。

最佳答案

来自MSDN :

The statement before the THROW statement must be followed by the semicolon (;) statement terminator.

关于sql-server - 'THROW' 附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35003153/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com