Get RETURN value from stored procedure in SQL

后端 未结 3 877
渐次进展
渐次进展 2021-02-02 04:59

I have a stored procedure where it ends with a RETURN value of 0 or 1.

I want to use this value in an IF statement in another stored procedure.

How can I get the

相关标签:
3条回答
  • 2021-02-02 05:35

    This should work for you. Infact the one which you are thinking will also work:-

     .......
     DECLARE @returnvalue INT
    
     EXEC @returnvalue = SP_One
     .....
    
    0 讨论(0)
  • 2021-02-02 05:43

    The accepted answer is invalid with the double EXEC (only need the first EXEC):

    DECLARE @returnvalue int;
    EXEC @returnvalue = SP_SomeProc
    PRINT @returnvalue
    

    And you still need to call PRINT (at least in Visual Studio).

    0 讨论(0)
  • 2021-02-02 05:49

    Assign after the EXEC token:

    DECLARE @returnValue INT
    
    EXEC @returnValue = SP_One
    
    0 讨论(0)
提交回复
热议问题