• I got it working by adding a 5th single quote to the line:

    FROM #DBFRAGMENT where ltrim(rtrim(#DBFRAGMENT.indexname))<> ''''

    Dave H