SQL @@ERROR
Syntax @@ERROR returns integer
Execution of a Transact-SQL statement, @@ERROR is set to 0 if the
statement executed successfully.
RETURN an
integer that represents the error. IF an error occurs, I typically use a negative integer to represent errors or
problems that have occurred when working with a SQL database.
Because @@ERROR is cleared and reset on each statement executed,
check it immediately following the statement validated, or save it to a
local variable that can be checked later.
-- Execute the INSERT, UPDATE or DELETE statement.
INSERT INTO authors
(au_id, au_lname, au_fname, phone, address,
city, state, zip, contract) values
(@au_id,@au_lname,@au_fname,@phone,@address,
@city,@state,@zip,@contract)
-- Test the error value.
IF @@ERROR <> 0
BEGIN
RETURN(-100) -- return a integer that represents the
error location in your code.
END
ELSE
BEGIN
RETURN(0)
END
GO
|
|