tmajor99
asked on
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)))
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)))
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)))
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)))
tmajor99, do you still need help with this question?
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..
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 firstOpen in new window