T-SQL:列出作用域中的所有变量

时间:2018-06-21 10:22:50

标签: sql sql-server tsql

我试图在异常发生后打印SP执行范围内的所有变量,以便对故障期间发生的错误有更多了解。你该怎么做?

BEGIN TRY
    DECLARE @Var1 AS VARCHAR(MAX) = 'variable 1'
    DECLARE @Var2 AS INT = 5
END TRY
BEGIN CATCH
    SELECT  @ErMessage = ERROR_MESSAGE(),
            @ErSeverity = ERROR_SEVERITY(),
            @ErState = ERROR_STATE();

    RAISERROR(@ErMessage, @ErSeverity, @ErState);

    -- Print all @variable values like "@Var1: variable 1, ..."

    RETURN -1
END CATCH

0 个答案:

没有答案