In this post, I will explain How to get @@ERROR and @@ROWCOUNT at the same time?
If @@ROWCOUNT is checked after Error checking statement, then it will have 0 as the value of @@ROWCOUNT will get reset. And if @@ROWCOUNT is checked before the error-checking statement then @@ERROR will get reset.
1) In this case @@ERROR will be “0”
SELECT @RC = @@ROWCOUNT
SELECT @ER = @@ERROR
2) In this case @@ROWCOUNT will be “0”
SELECT @ER = @@ERROR
SELECT @RC = @@ROWCOUNT
To get @@ERROR and @@ROWCOUNT at the same time do both in same statement and store them in local variable.
SELECT @RC = @@ROWCOUNT, @ER = @@ERROR