SQL Select Query to save results to another table

I need a SQL Select command that will save my results to a SQL Server table.   I want the results from the query below inserted into a new SQL Server table.

SELECT        PRODUCT, DESCRIPTION, HIERARCHY
FROM            F_MASTER
WHERE        (HIERARCHY NOT IN
                             (SELECT        GLBL_PROD_HIER
                               FROM            F_STEP_Level4
                               WHERE        (F_MASTER.HIERARCHY = GLBL_PROD_HIER)))
tmajor99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
just do this:
- create the table
- use the following command:
insert into <table name> (<field1>, <field2>, <field3>)
SELECT        PRODUCT, DESCRIPTION, HIERARCHY
FROM            F_MASTER
WHERE        (HIERARCHY NOT IN
                             (SELECT        GLBL_PROD_HIER
                               FROM            F_STEP_Level4
                               WHERE        (F_MASTER.HIERARCHY = GLBL_PROD_HIER)))

Open in new window

0
Mark ElySenior Coldfusion DeveloperCommented:
INSERT INTO Name of yourTable
     (PRODUCT, DESCRIPTION, HIERARCHY)
SELECT PRODUCT, DESCRIPTION, HIERARCHY
FROM            F_MASTER
WHERE        (HIERARCHY NOT IN
                             (SELECT        GLBL_PROD_HIER
                               FROM            F_STEP_Level4
                               WHERE        (F_MASTER.HIERARCHY = GLBL_PROD_HIER)))
0
Walter RitzelSenior Software EngineerCommented:
Or if you want to create a new table from this select:
SELECT        PRODUCT, DESCRIPTION, HIERARCHY
into new_table
FROM            F_MASTER
WHERE        (HIERARCHY NOT IN
                             (SELECT        GLBL_PROD_HIER
                               FROM            F_STEP_Level4
                               WHERE        (F_MASTER.HIERARCHY = GLBL_PROD_HIER)))

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
<minor addition to the above correct answers>

If you're going to be creating tables on the fly in this manner and planning on running it multiple times, make sure the table does not exist before you create it, or else it will throw an error..
IF OBJECT_ID('new_table') IS NOT NULL
   DROP TABLE new_table
GO

SELECT PRODUCT, DESCRIPTION, HIERARCHY
into new_table   --- blah blah blah

Open in new window

Or if you go the pre-existing table and INSERT, might not be a bad idea to remove all previous rows first
TRUNCATE TABLE new_table

INSERT INTO new_table --- blah blah blah

Open in new window

0
awking00Commented:
Using into clause should do it -
SELECT        PRODUCT, DESCRIPTION, HIERARCHY
INTO NEW_TABLE

 FROM            F_MASTER
 WHERE        (HIERARCHY NOT IN
                              (SELECT        GLBL_PROD_HIER
                                FROM            F_STEP_Level4
                                WHERE        (F_MASTER.HIERARCHY = GLBL_PROD_HIER)))
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
tmajor99, do you still need help with this question?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.