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
Try ##temp Because your dynamic query is executed on an other fibre so you cannot see its local temporay table. instead if you declare your temporary table like global it make a sens.