SQL SERVER QUERY

  • Hi all,

    I have some query regarding sql server 2005.

    whenver I try this,I am getting the o/p as

    Jumping To Branch One

    Jumping To Branch Two

    Eventhough the condition fails the in the if condition ,it still goes to the lables.why is it so?please Comment on this

    DECLARE @c1 int

    DECLARE @c int

    SET @c= 1

    SET @c1 = 2

    IF @c= 0

    begin

    GOTO Branch_One

    end

    IF @c1=3

    begin

    GOTO Branch_Two

    end

    Branch_One:

    print 'Jumping To Branch One'

    Branch_Two:

    print 'Jumping To Branch Two'

  • A goto will jump to a point in code , that code will still be executed as the flow of the program naturally passes it ,that is what has happened here.



    Clear Sky SQL
    My Blog[/url]

  • Instead of using GOTO I'd recommend you either include those code sections directly into the related IF block. If there's too much code, use separate sprocs and call those.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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