• smw147 (9/15/2014)


    Thanks all. The CTE and rbednarek's solution both worked.

    The question now is, what did the changes do to performance and resource usage? The reason I ask is that a common technique for fixing performance and resource usage problems associated with many "all in one queries" is to split up the query and put the essential "driver rows" into a temp table and include that in the join.

    To be sure, "Set Based" coding is the way to go but it doesn't mean "All in one query".

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