Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

How can I create a temp table and insert data from a query easily?

I'd like to insert data from a query into a temp table in the simplest manner.  I've looked at INSERT INTO SELECT, but it looks like the source data has to be from a table.  There's got to be a way to do this without cursors, right?  Thanks!
0
jvalescu
Asked:
jvalescu
1 Solution
 
Patrick MatthewsCommented:
Hello jvalescu,

The quick and dirty way:

SELECT
INTO #temp_table_name
FROM
WHERE

Otherwise, first you have to use CREATE TABLE to make the temp table, and then an INSERT INTO to
populate the temp table.  However, the CREATE/INSERT approach allows complete control over the table
design.

Regards,

Patrick
0
 
jvalescuAuthor Commented:
Thanks!
0
 
dqmqCommented:
>but it looks like the source data has to be from a table.

Not true.  the query will act just like a table:

Select * into #temp_table
from (select ... your query goes here)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now