@@ERROR in SQL SERVER
@@ERROR returns zero if the last executed statement did not throw an error, else it will return an error number.
The below shows a error message with error number when an Divide by Zero is encountered.
CREATE PROCEDURE ErrorNumber
AS
BEGIN
DECLARE @ErrorNumber varchar(20)
SELECT 1/0
SET @ErrorNumber = @@ERROR
PRINT 'Error Generated : ' + @ErrorNumber
END
The below shows a error message with error number when an Divide by Zero is encountered.
CREATE PROCEDURE ErrorNumber
AS
BEGIN
DECLARE @ErrorNumber varchar(20)
SELECT 1/0
SET @ErrorNumber = @@ERROR
PRINT 'Error Generated : ' + @ErrorNumber
END
Comments