Incorrect syntax near 'THROW'

前端 未结 3 753
一生所求
一生所求 2020-12-17 07:56
IF @SQL IS NOT NULL
BEGIN
    BEGIN TRY 
        EXEC sp_executesql @SQL
        PRINT \'SUCCESS: \' + @SQL
    END TRY 
    BEGIN CATCH
        SET @ErrorMessage =          


        
相关标签:
3条回答
  • 2020-12-17 08:39

    From the Documentation on THROW, Remarks:

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

    It's a good habit to always end your statements with a semi-colon.

    0 讨论(0)
  • 2020-12-17 08:43

    I just hit the same error but for a completely different reason. The machine I'm using is slightly old but has SSMS 2012 (the version that THROW was introduced). However the actual SQL server is 10.5 (which is 2008 R2; see https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level) and so the command is not valid.

    Hopefully there won't be too many instances of ten year old setups out there but double check if you get this and you're sure your syntax is correct!

    0 讨论(0)
  • 2020-12-17 08:47

    From MSDN:

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

    0 讨论(0)
提交回复
热议问题