Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Order should I Call @@ROWCOUNT/@@ERROR

Tags:

sql

t-sql

I am inserting a number or rows into a table using INSERT with SELECT. After the transaction, I want to store both the @@ROWCOUNT and @@ERROR values into locallay declared variables.

INSERT SubscriberList (PublicationId, SubscriberId)
SELECT @PublicationId, S.SubscriberId
FROM Subscribers S

SET @NoRows = @@ROWCOUNT
SET @ErrorCode = @@ERROR

I wasn't sure if this was valid in as much if I call one, will I negate the other?

like image 968
Neilski Avatar asked Sep 06 '25 02:09

Neilski


1 Answers

Set them both at once:

SELECT @NoRows = @@ROWCOUNT, @ErrorCode = @@ERROR

like image 173
JNK Avatar answered Sep 07 '25 21:09

JNK