How to get the error number?

Last Post 03 Aug 2006 08:53 PM by jmnobre. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
New Member
New Member

31 Jul 2006 09:33 PM
I had got the error message using @@spid function.
But I want to get the error number when there are more errors occured.
Can anyone help me to get the same.

Thank you.
New Member
New Member

03 Aug 2006 08:53 PM
Can't understand you... @@SPID returns the current process identifier not the current error... Assuming you mean the @@ERROR variable, this only returns the *last* error!
In theory you should test all your statements for an error, e.g.:


IF @@ERROR <> 0 BEGIN ... process this error here ... END


IF @@ERROR <> 0 BEGIN ... process this error here ... END


If you want to collect all your errors to report them in one go at the end... you have to do it on a statement basis, that is for example, use a temporary table to store each error (on the 'process this error here' in the sample above) and at the end, just report them!

Hope it helps

New Member
New Member

20 Aug 2006 01:30 AM
To help you, you have to provide us with the script.

@@spid is not a function.

It is a system variable.

Kalman Toth, Database, Data Warehouse and BI Architect
The Best SQL Server 2005 Training in the World

Acceptable Use Policy