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
|