Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unexpected Behavior with UPDATE and ERROR
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Unexpected Behavior with UPDATE and ERROR
Miscellaneous
Thread ID:
00455711
Message ID:
00455711
Views:
70
I am in the process of doing my first SQL Server project (version 7), and noticed something that strikes me as odd. Luckily, I have Mike Levy's article on stored procs from the Great Lakes Great Database Workshop. Basically, I am surprised that the following T-SQL statement:

UPDATE Company
SET Price = @Price
WHERE CompanyID = @CompanyID

Does not set @@ERROR

I have to check both @@ROWCOUNT and @@ERROR to see if the update was successful.

Also, right after the UPDATE statement, I cannot get the following to work:

SET @ErrorNo = @@ERROR, @RowCnt = @@ROWCOUNT

Instead, this must be on separate lines:

SET @ErrorNo = @@ERROR
SET @RowCnt = @@ROWCOUNT

The problem is that I think @@ROWCOUNT will be set to 1 after the SET @ErrorNo statement, so even if the UPDATE does not find the @CompanyID, @RowCnt will still be 1.
Chris McCandless
Red Sky Software
Next
Reply
Map
View

Click here to load this message in the networking platform