I tried the following (after making a table calles Results):
SELECT @sql = String FROM SQL_String
SET @sql = 'SELECT ev.Event_Name INTO dbo.Results' + CHAR(10) + @sql +
'FROM #Events ev ' + CHAR(10) +
'WHERE ev.event_year = @Year '
PRINT @sql
EXEC sp_executesql @sql, N'@Year int', @Year = @Edition_Year
but that does not work at all. The table has two fields: Event_Name and @sql.
I also tried the following:
SET @sql = 'SELECT ev.Event_Name' + CHAR(10) + @sql + 'INTO dbo.Results' +
'FROM #Events ev ' + CHAR(10) +
'WHERE ev.event_year = @Year '
with the same result. Nothing but errors.
What am I doing wrong?
Robert