Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Raise an exception from within a SP
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01076224
Message ID:
01076243
Views:
22
>>>>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

WhereRollBackIs:
  ROLLBACK TRANSACTION
Please let me know if you see anything (really) bad.

Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform