Solved

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

Posted on 2015-01-08
10
151 Views
Last Modified: 2015-01-08
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
0
Comment
Question by:Jass Saini
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 40538142
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).
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40538144
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.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538153
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
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:Jass Saini
ID: 40538193
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

0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40538206
Do the Make Table or Append in a different query, based on your above query.
0
 

Author Comment

by:Jass Saini
ID: 40538210
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.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538211
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

0
 

Author Comment

by:Jass Saini
ID: 40538231
I am getting a Syntax error in From clause
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40538245
if you have saved your crosstab quey, you can use

'create new table

SELECT crosstabquery.* INTO NewTable
FROM  crosstabquery

or
'append to your table
 
INSERT INTO NewTable
SELECT crosstabquery.*
FROM crosstabquery

change  "crosstabquery" with the name of the crosstab query
0
 

Author Closing Comment

by:Jass Saini
ID: 40538248
Thanks Rey....I will try that!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

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