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
Change is inevitable... Change for the better is not.