• GrassHopper (12/1/2014)


    Anyone think they can improve on this query?

    Almost no question. The key here is that your code now has two real tables in it. For my stuff to work, you'll need to post the code necessary to not only create the Temp Table like you did before, but also write the code that joins the two tables to populate it. Don't spend any time on trying to do aggregates. Just make it so that it populates the temp table with flat data like you did in your example. Post that query and then we can get you down to some probably much quicker code.

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