Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@@ERROR in SQL Server 2005

I have learned to use the SCOPE_IDENTITY() instead of just @@IDENTITYto get the last identity value inserted in a given scope, which can be quite useful in high-concurrency scenarios. Is there any equivalent to that function for the @@ERROR variable? I mean, is there any way to make sure that whenever I write

IF (@@ERROR <> 0) RETURN

I am in fact forcing the function to return because of the very last command in this scope caused an error?

like image 438
B.M Avatar asked Feb 15 '26 02:02

B.M


1 Answers

From Books Online:

@@ERROR only returns error information immediately after the Transact-SQL statement that generates the error.

@@Error is only within the current scope. So it should have the value for whatever sent the proc to the catch block no matter which of several statements was the one that errored.

like image 71
HLGEM Avatar answered Feb 16 '26 18:02

HLGEM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!