• Siobhan Perricone (3/8/2013)


    I got asked to not use a cursor for a loop that I'm working on so I grabbed the code here:

    http://www.sql-server-performance.com/2004/operations-no-cursors/%5B/quote%5D

    To emphasize what Gail has stated, they should outlaw articles like the one you provided the link for. Probably most important is the fact that the author has produced absolutely NO performance stats on the two methods and, like many of us had in the early days until we tested, has bought into the myth that Temp Tables or Table Variables and While loops are more efficient than Cursors. A well written "firehose" cursor is just as effecient and easier to code than such alternatives. It's usually a total waste of time to convert Cursors to alternatives. You won't actually believe it until you prove it to yourself with code.

    Don't buy into the "Cursor Replacement Myth" of replacing cursors with While Loops and Temp Tables. It usually makes no difference. If you feel you must, just convert the cursor to a "firehose" cursor and call it a day.

    What you should buy into, however, is that there's usually a very high performance method to avoid RBAR (see my sig line below for definition) altogether. Even multiple set-based passes on a Temp Table will blow any While loop away whether in a Cursor or not.

    --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)