Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I create a table based on a Query Result? 1

Status
Not open for further replies.

faust13

Programmer
Joined
Aug 7, 2001
Messages
176
Location
US
My DBMS is MSSQL:

I would like to create a table based on my query results, I don't know how to do it, any help is appreciated.

SELECT Col_A, Col_B, Col_C
FROM myTbl
WHERE someCriteria = unimportant

CREATE TABLE myNewTbl(
newCol_A int,
newCol_B int,
newCol_C int
)

With the query results going into the respective new columns in the new table.

Suggestions? ----------------------------------------
Is George Lucas Kidding...
 

Use a SELECT INTO query.

SELECT Col_A, Col_B, Col_C
INTO myNewTbl
FROM myTbl
WHERE someCriteria = unimportant Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
First create the table.

Then INSERT rows using the query like this

Code:
INSERT INTO myNewTbl (newCol_A, newCol_B, newCol_C)
    SELECT   Col_A, Col_B, Col_C
       FROM     myTbl
       WHERE    someCriteria = veryimportant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top