• Mitesh Oswal (9/4/2012)


    Hi ,

    Can you please try the below logic

    I did and, as expected, it contains a triangular join. Please see the following article for why that will be absolutely devestating to the server for larger rowcounts.

    http://www.sqlservercentral.com/articles/T-SQL/61539/

    Either use a Quirky Update, a recursive CTE that doesn't use a Triangular Join, or use a well formed static, forward only, read only cursor. It'll be a lot faster and a whole lot easier on recources than almost anything (there is an exception but don't have time to find it right now) that uses a Triangular Join.

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