• This is one of the old ways of doing things:

    DECLARE @Errorint

    --YourCode

    SET @Error = @@ERROR

    IF @Error = 0

    BEGIN

    --Success Code

    END

    ELSE

    BEGIN

    --Fail Code

    END

    It is very important that you set @Error after every single statement because @@ERROR changes after each one executes. I usually use something like this for making sure every statement in the batch executed successfully:

    SET @Error = CASE WHEN @Error = 0 THEN @@ERROR ELSE @Error END

    For example, even this would be bad logic:

    --YourCode

    If @@ERROR <> 0

    SET @Error = @@ERROR

    The problem with this is that the IF statement executed successfully and the new value of @@ERROR is 0 instead of whatever it was before.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]