Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save select query results within temporary table?

I need to save select query output into temporary table. Then I need to make another select query against this temporary table. Does anybody know how to do it?

I need to make this on SQL Server.

like image 739
truthseeker Avatar asked Dec 08 '10 19:12

truthseeker


People also ask

How do you store a result of query in a temp table in SQL?

You can use select ... into ... to create and populate a temp table and then query the temp table to return the result. No you don't. If you want to fill a table that already exist with rows you need to use a different syntax.

Where are SQL temporary tables stored?

Temporary tables are stored in tempdb. They work like a regular table in that you can perform the operations select, insert and delete as for a regular table. If created inside a stored procedure they are destroyed upon completion of the stored procedure.


1 Answers

select * into #TempTable from SomeTale  select * from #TempTable 
like image 157
Eric.K.Yung Avatar answered Sep 20 '22 16:09

Eric.K.Yung