Monday, May 04, 2015

How to get @@ERROR and @@ROWCOUNT at the same time?

Posted by Rahul Kharde at 9:43 AM


@@ERROR - variable shows the error number of the last T-SQL error @@ROWCOUNT- variable gives the number of rows affected by the most recent SQL statements. 

If @@ROWCOUNT is checked after @@ERROR checking statement then it will have 0 as the value of @@ROWCOUNT as it would have been reset.

if @@ROWCOUNT is checked before the error-checking statement then @@ERROR would get reset.  

Both run at same time and store them in local variable

 DECLARE @RC INT
 DECLARE @ER INT
 SELECT @RC =@@ROWCOUNT, @ER = @@ERROR
 SELECT @RC,@ER


If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top