• Thanks, Raja - this works great!

    A few mods:

    1. Changed the VARCHAR(8000) variables to VARCHAR(MAX) to avoid problem noted by another respondent.

    2. To handle ORDER BY clauses, I added code to split out that clause,

    then appended the variable containing it to the following statment:

    set @Final= 'Select '' '' into ##tempHTML2 from ##tempHTML1 '