• I like Lynn's approach of splitting it inline and keeping it to a single query instead of using temp tables. Also, his function will be usable elsewhere.