0

I need to push the results from this code below into a undefined TEMP table. Temp table must be undefined because I wont know the column names of the result set .

declare @sql varchar(4000)
set @sql ='Select * from #Test'

exec (@sql) 

--Need to insert the final result set into #TempTableName because I need to use it in code lower down in my Stored Procedure.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Etienne
  • 7,141
  • 42
  • 108
  • 160
  • Boils down to [this question](http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure "How to SELECT * INTO [temp table] FROM [stored procedure]"). – Andriy M Jul 31 '13 at 06:31

1 Answers1

0

Found the answer.............

Needed to use a Global Temp table and that did it for me.

declare @sql varchar(4000)
set @sql ='Select * INTO ##TempTableName from #Test'

exec (@sql) 

Select * from ##TempTableName 

The ## is for a global temp table and that worked for me.

Etienne
  • 7,141
  • 42
  • 108
  • 160