Solved

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

Posted on 2009-07-08
3
207 Views
Last Modified: 2012-05-07
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
Comment
Question by:jvalescu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24806332
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
 

Author Closing Comment

by:jvalescu
ID: 31601240
Thanks!
0
 
LVL 42

Expert Comment

by:dqmq
ID: 24806578
>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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question