Link to home
Start Free TrialLog in
Avatar of Jass Saini
Jass Saini

asked on

How to take results from an query and put them into a table

Hello,

I ran a query and would like the results of the query to into the table....I need to do this each time I run the query
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

The syntax for that would be something like

INSERT INTO TableB (Field1, Field2, Field3)
SELECT Field1, Field2, Field3
FROM TableA
WHERE Field1 = 2

All you really need to do is add the INSERT line, with the name of the table you want to append to, and the fields you want to place the output of your query in.  Making sure that the field types in TableB and the query must match (but the field names do not have to).
Avatar of Phillip Burton
Phillip Burton

Do you mean a new table or an existing table?

Go to Design Mode and

- If the former, click on "Make Table".
- If the latter, click on "Append".

Enter the table name.
I'll assume you are running a SELECT query
in design view of your query, change your SELECT query into an APPEND query
select the Destination table from the dropdown in the Append window

select the destination fields in the

Append to: row of the query
Avatar of Jass Saini

ASKER

Here is my query

TRANSFORM Sum(Final_Table.[Total Initial]) AS [SumOfTotal Initial]
SELECT Final_Table.[Org Name], Final_Table.[CostCen], Final_Table.Fund, Final_Table.PEC, Final_Table.BC1Chng1, Final_Table.BC2Chng1
FROM Final_Table
GROUP BY Final_Table.[Org Name], Final_Table.[CostCen], Final_Table.Fund, Final_Table.PEC, Final_Table.BC1Chng1, Final_Table.BC2Chng1
PIVOT Final_Table.[Line Item];

Open in new window

Do the Make Table or Append in a different query, based on your above query.
Rey,

I tried that ...I have 900 records and this is a crosstab and when I change to an append query...it wanted to append 7124 records.  That not what I want.
create a new query (DO NOT select any table), go to SQL view

copy the below sql and paste to the new query
select A.* Into NewTable
From
(
TRANSFORM Sum(Final_Table.[Total Initial]) AS [SumOfTotal Initial]
SELECT Final_Table.[Org Name], Final_Table.[CostCen], Final_Table.Fund, Final_Table.PEC, Final_Table.BC1Chng1, Final_Table.BC2Chng1
FROM Final_Table
GROUP BY Final_Table.[Org Name], Final_Table.[CostCen], Final_Table.Fund, Final_Table.PEC, Final_Table.BC1Chng1, Final_Table.BC2Chng1
PIVOT Final_Table.[Line Item]
) As A

Open in new window

I am getting a Syntax error in From clause
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rey....I will try that!