0 - 1 of 1 tags for Query rewriting

Hi All,
I have two versions(One is old which is being rewritten using some new standards) of code both claiming to accomplish the same thing; with the subset of data we tested both seems to give the same results. If you guys see any issues in the new code, pelase let me know.
 
Old Code: