• The Tally table cannot be used to solve ranking problems because of the inherent cross-join. You've limited the cross-join, but only with a triangular join... half as bad but still very bad.

    There's no such thing as "Physical Order" in a database. You can have an implied order based on an index, but unless it's a Clustered index, you can end up with the "merry-go-round" order that I spoke of in the Running Total article.

    What is the Clustered index of the table, Karthik? If there isn't one and the MID column can't be used to establish the "natural" order (as you've already stated), this problem cannot be solved. Sorry...

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