Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 17th, 2006, 03:31 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Corey
Default Union Qry

Hello again.

If anyone can help me it would be greatly appreciated.
I’m not sure shy I’m having so much trouble with this, but I’m sure that this will be a great learning opportunity for me.

I’ll explain it two different ways, and that way hopefully it will make sense

First off I’m trying to take all the Companies I work with and get there Net Sales

Example:
Company 1 $1,625.25
Company 2 $6,782.12
ect

I have two queries

The first one is:
qrtySym_Global_ALL_and_SUBFILE_A3

The second one is:
FROM qrtySym_Global_ALL_and_SUBFILE_A4

Below is the Union Query I currently have, and it puts together both queries and shows the totals separately

I would like it to show the Company Name and next to that the Net Sales for that company


SELECT "Total" , Sum(NETSALES)
FROM qrtySym_Global_ALL_and_SUBFILE_A3
union All
SELECT "Total" , Sum(NETSALES)
FROM qrtySym_Global_ALL_and_SUBFILE_A4


Let me see if I can explain it better

The are three columns in the two queries that are the same.

Company Business/ Company Name/Net Sales

I’m trying to take all the

A: Company Business that has the same name from query 1 and query 2 and merge them.

B: Company Name that has the same name from query 1 and query 2 and merge them.

C: Then with the merging of Company Business and the Company Name, Sum the total for the Net Sales.

I really appreciate you helping, so let me know if this doesn’t make sense

Thanks

Corey


 
Old November 20th, 2006, 06:21 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Corey,

Given that you have used a pair of queries to prepare the data, can I guess that the data comes from the same table initially? If so there is a much easier and more straight-forward way to do this.

Either way, this is virtually the method for both cases:

You seem to want a group sum of Company Business and Name, summing the Net Sales field... so:

SELECT Table1.[Company Business]
     , Table1.[Company Name]
     , Sum(Table1.[Net Sales]) AS [Total]
FROM Table1
GROUP BY Table1.[Company Business]
       , Table1.[Company Name]

should do the trick, you will need to change the table/query name, obviously. You will need one of these for each table/query for incorporate and just seperate them by "UNION".

If you are using queries to seperate data out of one single table, then just delete the queries and use this directly, then add in your criteria as per your original queries.

Hope it helps.
Lee





Similar Threads
Thread Thread Starter Forum Replies Last Post
Qry result to xls97 worksheet? len Excel VBA 0 August 25th, 2005 01:12 PM
Qry to retrieve from 2 tables and display tsimsha Classic ASP Databases 3 October 29th, 2004 02:03 AM
cmd.qry mohiddin52 Access 0 December 29th, 2003 08:49 AM
command button qry mohiddin52 Access 0 December 22nd, 2003 08:20 AM
Prb: COUNT qry result NOT SAME as SELECT qry savoym SQL Language 5 July 2nd, 2003 04:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.