Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How many rows were affected?
Message
De
07/12/2005 16:01:43
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01075860
Message ID:
01075889
Vues:
36
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform