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 the former stored procedure and save it in a variable in the latter?
I couldn't find anything related. All questions are about fetching the 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
Return Value in SQL Server Stored ProcedureIn default, when we execute a stored procedure in SQL Server, it returns an integer value and this value indicates the execution status of the stored procedure. The 0 value indicates, the procedure is completed successfully and the non-zero values indicate an error.
SQL Server allows to return a single integer value from a Stored Procedure using the RETURN keyword. The Return keyword is supported in Stored Procedures of all SQL Server versions i.e. 2000, 2005, 2008, 2008R2, 2012 and 2014.
You can use one or more RETURN statements in a stored procedure. The RETURN statement can be used anywhere after the declaration blocks within the SQL-procedure-body. To return multiple output values, parameters can be used instead. Parameter values must be set before the RETURN statement runs.
This should work for you. Infact the one which you are thinking will also work:-
....... DECLARE @returnvalue INT EXEC @returnvalue = SP_One .....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With