How SQL query result insert in temp table? [duplicate]
Solution 1:
Look at SELECT INTO. This will create a new table for you, which can be temporary if you want by prefixing the table name with a pound sign (#).
For example, you can do:
SELECT *
INTO #YourTempTable
FROM YourReportQuery
Solution 2:
You can use select ... into ...
to create and populate a temp table and then query the temp table to return the result.
select *
into #TempTable
from YourTable
select *
from #TempTable
Solution 3:
In MySQL:
create table temp as select * from original_table
Solution 4:
Try:
exec('drop table #tab') -- you can add condition 'if table exists'
exec('select * into #tab from tab')