RETURN also allows for an optional integer expression: : Return « Transact SQL « SQL Server / T-SQL Tutorial






RETURN [ integer_expression ]

This integer value can be used in a stored procedure to communicate issues to the calling application.

 Create a Stored Procedure that raises an error
9> CREATE PROCEDURE #usp_TempProc
10> AS
11> SELECT 1/0
12> RETURN @@ERROR
13> GO
1>
2> DECLARE @ErrorCode int
3>
4> EXEC @ErrorCode = #usp_TempProc
5> PRINT @ErrorCode
6> GO
Msg 8134, Level 16, State 1, Server BCE67B1242DE45A\SQLEXPRESS, Procedure #usp_TempProc_________________________________
__________________________________________________________________________00000077, Line 11
Divide by zero error encountered.

(0 rows affected)
8134








20.22.Return
20.22.1.RETURN is used to exit the current Transact-SQL batch, query, or stored procedure immediately.
20.22.2.RETURN also allows for an optional integer expression:
20.22.3.How to Use RETURN
20.22.4.Return statement
20.22.5.Return a table from a function
20.22.6.RETURNS a TABLE with structure
20.22.7.Assign returned value from a function to a declared variable