Error control and transaction handling (please correct me)

  • Hi Everyone

    I have a code here which for some reason branches to the GOTO statement, I think there is something wrong within the code itself, can someone help me re-write it properly, I want to have transactional handling and error control at thesame time.

    Also, transactional handling tends to fail with an open transaction if the table isn't present, is this a normal behaviour ?

    Create procedure SpTest

    as

    Begin

    BEGIN TRAN

    Select top 10 name into #temp from sysobjects

    IF @@ERROR <> 0

    GOTO ErrorControl

    COMMIT

    ErrorControl:

    Print 'There was an error'

    ROLLBACK

    End

  • The chances are it's not branching to the GOTO, but dropping into it. You need to put a RETURN immediately after the COMMIT.

Viewing 2 posts - 1 through 1 (of 1 total)

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