Get RETURN value from stored procedure in SQL

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 return value of a previous stored procedure and store it in a variable in the last?

I could not find anything related. All questions relate to getting RETURN values โ€‹โ€‹in C #.

I was thinking maybe something like this:

SP_Two

DECLARE @returnValue INT SET @returnValue = EXEC SP_One IF @returnValue = 1 BEGIN --do something END ELSE BEGIN --do something else END 
+45
sql sql-server
Nov 28 '12 at 12:35
source share
3 answers

This should work for you. Infact the one you think will also work: -

  ....... DECLARE @returnvalue INT EXEC @returnvalue = SP_One ..... 
+53
Nov 28 '12 at 12:40
source share

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

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

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

+13
Oct 17 '13 at 19:59 on
source share

Assign after EXEC token:

 DECLARE @returnValue INT EXEC @returnValue = SP_One 
+5
Nov 28 '12 at 12:42 on
source share



All Articles