• Madhivanan-208264 (9/7/2010)


    Have a million row table and do running total using a triangular join

    select col,

    (select sum(col) from table as t1 where t1.pkcol<=t2.pkcol) as run_sum

    from table as t2

    Heh... ya beat me to it, Madhivanan.

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