Consider the following code:
SET @SQL1 = \'SELECT * INTO #temp WHERE ...\' exec(@SQL1) SELECT * from #temp (this line throws an error that #temp doesn\'t ex
Can you not put your select after the insert into with a ; delimeter and run the two statements together?