Comapre records using cursor

  • ashisht4u (12/12/2011)


    Lynn,

    Actually I'm preparing for my interview and I came across some of the question on DB, I'm at C++ but not done much work on SQL-Server. I want to learn db scripting.

    Sean,

    Can you provide some more information on how could I implement this without using cursor.

    Your help on this is appreciated.

    Self join on the table using ROW_NUMBER to create a sequence. Join would be offset by 1 on that ROW_NUMBER sequence.

    As a side bar, the only questions I ask about a Cursor is "When would you use one?" If the answer isn't "Almost never", then you've given the wrong answer. The next question to follow would be "Except for the almost never occasions, when would you use one?" I'll leave the answer to that question for you to discover on your own. 😉

    --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 post 16 (of 16 total)

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