sql-server – “THROW”附近的语法错误

前端之家收集整理的这篇文章主要介绍了sql-server – “THROW”附近的语法错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@
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’.

用打印@ErrorMessage替换THROW.

文字字符串替换@ErrorMessage变量可以工作.

然而,根据文档,THROW应该能够使用变量.不知道该怎么做

解决方法

MSDN

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

原文链接:https://www.f2er.com/mssql/75668.html

猜你在找的MsSQL相关文章