t-sql 2008 r2 performance

  • In t-sql 2008 r2, can you tell me what performs better from the following two options and why:

    1. If parameter value = '1'

    goto parm1

    else of parameter value = '2'

    goto parm2

    goto final

    parm1:

    <do something1>

    goto final

    parm2:

    <do something2>

    final:

    2. If parameter value = '1'

    <do something1>

    else of parameter value = '2'

    <do something2>

  • I don't believe that there's a performance difference. However, I'm not sure why would anyone use so many gotos, seems like spaghetti code for me.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I would go for option 2. More concise and less confusing.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • wendy elizabeth (10/10/2013)


    In t-sql 2008 r2, can you tell me what performs better from the following two options and why:

    1. If parameter value = '1'

    goto parm1

    else of parameter value = '2'

    goto parm2

    goto final

    parm1:

    <do something1>

    goto final

    parm2:

    <do something2>

    final:

    2. If parameter value = '1'

    <do something1>

    else of parameter value = '2'

    <do something2>

    I agree with the others... there is no real difference in peformance so I'd go with the simplicity and inherent readability of option 2.

    However, it may be that neither is actually appropriate. What is the "do something" in each case?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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