Create a Stored Procedure that raises an error : Error « Transact SQL « SQL Server / T-SQL






Create a Stored Procedure that raises an error



3> CREATE PROCEDURE #usp_TempProc
4> AS
5> SELECT 1/0
6> RETURN @@ERROR
7> GO

1>
2> DECLARE @ErrorCode int
3> EXEC @ErrorCode = #usp_TempProc
4> PRINT @ErrorCode
5> 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
1>
2> drop procedure #usp_TempProc
3> GO

 








Related examples in the same category

1.A simple example of the @@ERROR variable
2.Use @Error
3.Rollback transaction on error