• (1) Remove one of the )s from the last line.

    (2) that last "FROM SOLICIT.gtm_doc" bit - does that belong to the SELECT MAX(D.sent_date) bit?  because you've already got a FROM in the CROSS APPLY...

    Thomas Rushton
    blog: https://thelonedba.wordpress.com