Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How many rows were affected?
Message
From
07/12/2005 16:01:43
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01075860
Message ID:
01075889
Views:
42
>Considder the following SP:
>
>BEGIN TRAN
>
>UPDATE mytable
>  SET Name = @Name1
>  WHERE Id = @Id1
>
>UPDATE mytable
>  SET Name = @Name2
>  WHERE Id = @Id2
>
>UPDATE mytable
>  SET Name = @Name3
>  WHERE Id = @Id3
>
>
>COMMIT TRAN
>
>
>Id is PK.
>Lets say there is a match for Id = @Id1 and for Id = @Id3, but there are no matches for Id = @Id2. If this is the case I want to roll back the first update and not preceed with the 3rd update, then I want to report back to the application that either 0 records were affected or maybe even better that an exception was raised.
>
>How can I caputure if any records where affected after each update and continue if 1 row was affected and roll back and not proceed if 0 rows were affected?
>
>Any assistance on this would be greatly appreciated.
>
>Einar

Einar,

Nest the conditionals and check @@ROWCOUNT after each update.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform