Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Raise an exception from within a SP
Message
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:
01076224
Message ID:
01076261
Vues:
23
Thanks Fabio.

Einar

>>Fabio,
>>I didn't see that you wrote anything to me. It might have gotten lost in all the other replies.
>>
>look
>RETURN
>for.
>
>>Einar
>>
>>>>>>>>Can I raise an exception from within a SP? If yes, how?
>>>>>>>>
>>>>>>>>Einar
>>>>>>>>
>>>>>>>>UPDATE: Is RAISEERROR the correct way to go about this?
>>>>>>>
>>>>>>>Yes.
>>>>>>
>>>>>>Thanks Sergey. It seems like I will keep you busy today :)
>>>>>
>>>>>Warning: RAISEERROR doesn't stop the SP execution
>>>>
>>>>Thanks for warning me Fabio. That was my follow-up question for Sergey. (I guess I kinda noticed that because in the documentation they put ROLLBACK after RAISERROR).
>>>>How would you solve the problem of getting the SP to stop execution? Would you use GOTO?
>>>>
>>>>Something like this:
>>>>
>>>>UPDATE myTable SET Name=@Name1 WHERE Id=@Id1
>>>>IF @@ROWCOUNT=0
>>>>BEGIN
>>>>  RAISERROR('Error 1',16,1)
>>>>  GOTO WhereRollBackIs
>>>>END
>>>>
>>>>UPDATE myTable SET Name=@Name2 WHERE Id=@Id2
>>>>IF @@ROWCOUNT=0
>>>>BEGIN
>>>>  RAISERROR('Error 2',16,1)
>>>>  GOTO WhereRollBackIs
>>>>END
>>>>
>>>>UPDATE myTable SET Name=@Name3 WHERE Id=@Id3
>>>>IF @@ROWCOUNT=0
>>>>BEGIN
>>>>  RAISERROR('Error 3',16,1)
>>>>  GOTO WhereRollBackIs
>>>>END
>>>>
>>>>COMMIT TRANSACTION
>>>>
>>>RETURN
>>>
>>>>WhereRollBackIs:
>>>>  ROLLBACK TRANSACTION
>>>>
>>>>
>>>>Please let me know if you see anything (really) bad.
>>>>
>>>>Einar
Semper ubi sub ubi.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform