You need to declare and assign @col1 within the dynamic SQL. Or drop the @ if you just meant col1
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