Translate

Monday 31 March 2014

select into Temp table from dynamic sql

set @SQL=('SELECT * into #temp FROM TableName; SELECT * FROM #TEMP')
exec(@SQL)

or

set @SQL=('SELECT * into ##temp FROM TableName')
select * from ##temp
Drop Table  ##temp

or

CREATE TABLE #temp (iid int, strName varchar(100), strAge varchar(100), str varchar(100), strTitle varchar(100))

exec('insert into #temp SELECT * FROM tbl_XML_Test')

select * from #temp

drop table #temp

Note: we can, t use table variable  instead of temp table for above query.