SQL Server Articles

Submit Article
Home » Articles » SQL Server » System FunctionsRSS Feeds

@@ERROR - ERROR Function

Posted By: Sarita Patel     Category: SQL Server     Views: 2506

This article explains about @@ERROR function in sql server with examples.

@@ERROR function returns error number of last sql statement executed.

It is a nondeterministic i.e It returns different value every time it is called with a specific set of values.

Syntax of @@ERROR Function :


Return type of @@ERROR function is an integer. @@ERROR is set to 0 if the statement executed successfully otherwise error number.  

Examples of @@ERROR Function :

Example 1 : Use of @@ERROR function after executing select clause 

SELECT  ProductName, UnitsPrice
FROM     Products

IF (@@ERROR > 0)
SELECT error, description FROM master.dbo.sysmessages WHERE error = @@ERROR

error    description
207      Invalid column name '%.*ls'.

Above example returns error number and description of executed sql statement.



Didn't find what you were looking for? Find more on @@ERROR - ERROR Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of @@ERROR - ERROR Function is from United States.
View All Articles

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

No Comment Found, Be the First to post comment!