Adding running number on groups of records in a table

  • Jeff Moden (1/9/2009)


    Heh... ah yes... THAT one. And because I'm a professional, I'm also supposed to be nice in the face of such abuse. I rewrote that one about 5 times trying to be nice. What it really needed was a barrage of high speed pork chops. πŸ˜›

    How'd I do? :hehe:

    Considering you're giving up the weed an' all, commendably well. I'd have bitch-slapped with a beef rib, and I still smoke. Well, if I rub it fast enough.

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Jeff, I think you handled that one very well. It is one that could have gotten nasty. I'd make another comment, but...

    Hey, while I'm here, have you tested the code yet??

  • BWAA-HAAA!!! Everything that comes around, goes around. Talk about nearly instant gratification... Pork chops... AWAY!! πŸ˜›

    http://qa.sqlservercentral.com/Forums/Topic632886-149-1.aspx?#BM633444

    I feel MUCH better, now. πŸ˜‰

    --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)
    Intro to Tally Tables and Functions

  • Had to add to it, a small reward for not allowing myself to respond the other day when I first that post :hehe:.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. πŸ˜‰

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Garadin (1/9/2009)


    Had to add to it, a small reward for not allowing myself to respond the other day when I first that post :hehe:.

    Oh, very well done, Seth. Thanks for helping me straighten Grant out. :P:P:P

    --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)
    Intro to Tally Tables and Functions

  • Jeff Moden (1/9/2009)


    BWAA-HAAA!!! Everything that comes around, goes around. Talk about nearly instant gratification... Pork chops... AWAY!! πŸ˜›

    http://qa.sqlservercentral.com/Forums/Topic632886-149-1.aspx?#BM633444

    I feel MUCH better, now. πŸ˜‰

    Good to see you back in a good mood! You're no fun when your grumpy!:w00t:

  • Lynn Pettis (1/9/2009)


    Good to see you back in a good mood! You're no fun when your grumpy!:w00t:

    Opportunities to hurl some well deserved pork overhand always bring the best out in me. πŸ˜€ I sure do hope that Grant picks up on the irony.

    And, no... haven't tested your code, yet, Lynn... I'm gonna try to get to that tonight. Thank you for your patience.

    --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)
    Intro to Tally Tables and Functions

  • Man... talk about "hijacking a thread"... sorry about that, folks. It was a much needed attitude repair.

    --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)
    Intro to Tally Tables and Functions

  • Jeff Moden (1/9/2009)


    Lynn Pettis (1/9/2009)


    Good to see you back in a good mood! You're no fun when your grumpy!:w00t:

    Opportunities to hurl some well deserved pork overhand always bring the best out in me. πŸ˜€ I sure do hope that Grant picks up on the irony.

    And, no... haven't tested your code, yet, Lynn... I'm gonna try to get to that tonight. Thank you for your patience.

    Not a problem. I haven't heard anything more from Steve yet. He probably hasn't had much time to read it yet.

Viewing 9 posts - 31 through 38 (of 38 total)

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