• ZZartin (11/21/2014)


    g.britton (11/21/2014)


    ScottPletcher (11/21/2014)


    You don't "have" to do the FETCH twice. In fact, I never do that, because it's too error prone when the code is changed.

    good point, though the standard examples tend to have two FETCH statements.

    /shrug it's a very intuitive way to code it, and the risk that someone might forget to update one of the fetch statements should be pretty obvious pretty fast when(hopefully) the code is tested.

    I wonder if maybe the "two fetch" statements protect against problems with a cursor definition that returns an empty set (no rows)? If you use the two fetch statements, does the immediate "while" test after the first "fetch next" catch a cursor returning no rows? If so then I'm guessing with "one fetch", you'll then need two tests against @@fetch_status if you really want to catch an empty row situation.