Take this lot out from just before the exec. The GO breaks the batch and afterwards, the SQL1... variables are not defined.
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
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