Error checking/ignoring

  • Hello all,

    I have a stored procedure with a series of update statements.

    --Update statement 1

    UPDATE.....

    --Update statement 2

    UPDATE.....

    If update 1 fails I still want update 2 to run. Is this possible?

  • Emily,

    My recommendation would be to encapsulate each Update in a BEGIN TRY...END TRY / BEGIN CATCH...END CATCH block.

    If you are on a pre-SQL 2005 install, this won't be available to you so you'll have to settle for checking the error code after each statement and hoping you don't run into a statement that ends the batch/proc before error-checking can be done.

  • BEGIN TRY functionality is awesome, but alas I am on 2000.

  • If you don't mind doing a bit of reading, Erland Sommerskog has one of the better write-ups on SQL Server error handling:

    http://www.sommarskog.se/error-handling-I.html

    About a third of the way down the section "When does SQL Server take which action?" has a table with the error behavior of a number of common errors, most of which are probably applicable to your UPDATE statement(s).

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply