Edit. I need to read better.
A better way to debug than mess with dynamic SQL, which in this case is going to cause errors that didn't exist before, is to take the queries and run them one by one in QA/Management studio.
Just declare the necessary variables, and run the queries alone.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability