Solved

Count values in a query

Posted on 2012-12-27
7
317 Views
Last Modified: 2012-12-27
I have a query in which I query ten tables for cross reference information.

Each table has
Item_nr
Vendor_item_nr
Price

My master table has
Item_nr
30 other fields

My query selects Vendor_item_nr from each table where Item_Nr=tbl_master!item_nr

My results
Item_nr, tbl_1!Vendor_item_nr, tbl_2!Vendor_item_nr, tbl_3!Vendor_item_nr...ect

How can I count the number of Vendor_item_nr results returned for each Item_nr?
0
Comment
Question by:MCaliebe
  • 3
  • 2
  • 2
7 Comments
 
LVL 26

Assisted Solution

by:jerryb30
jerryb30 earned 100 total points
ID: 38724747
SELECT master.item_nr, table1.vendor_item_nr, "table1" AS Source
FROM master INNER JOIN table1 ON master.item_nr = table1.item_nr
union all
SELECT master.item_nr, table2.vendor_item_nr, "table2" AS Source
FROM master INNER JOIN table2 ON master.item_nr = table2.item_nr
union all
SELECT master.item_nr, table3.vendor_item_nr, "table3" AS Source
FROM master INNER JOIN table3 ON master.item_nr = table3.item_nr

etc

Then:
Select Item_nr, count(vendor_item_nr) from yourQuery
group by item_nr
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724748
You need to  get rid of the 10 separate (Vendor) tables and normalize that data into a single table with fields:

VendorID
Item_nr
Vendor_item_nr
Price

With that type of a structure, you simply count the number of VendorID values for each Item_Nr.

You could accomplish the same thing with a normalizing query, but having separate tables for each vendor makes the entire database application far more complex than it needs to by.
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38724750
Meant to say: Create a union query, and use as source of count query.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:MCaliebe
ID: 38724778
I was given each vendor as it's own spread sheet.  I admit I thought about putting them all together, however not all the vendors use a unique vendor_item_nr so I could have 3 vendors with unique Vendor_item_nr and 3 using the same. I needed to keep each record identified back to the vendor as well.  Some vendors have multiple prices as well.
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 150 total points
ID: 38724823
A lot of vendors have multiple prices based on the way the items are packaged, so create a single table with:

VendorID
Item_nr    'I assume this is your item number
Vendor_item_nr
Pckg          'this might be 'each', 'Pack of 10', 'Pack of 100', 'Box of 500'  whatever
Price

and vendor prices will also change, so it is common to include an Effective Date (and possibly Thru Date) in tables like this so you can keep track of the effective date of a price and how long it is good for.
0
 

Author Closing Comment

by:MCaliebe
ID: 38724850
Although I'm certain Jerry's solution would work, I think the best solution for me is to do as fyed suggest and try to combine this data in a more data friendly format.  I'll probably have to ask this questions again, however at this time...I'll work with the data.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724880
You can use Jerry's union query to get the data into a normalized format I recommended.  That is where you need to start.  Then create a Make-Table query from the union query to create the new normalized table.  As long as you don't delete the original 10 vendor tables, you can tweak that union query until you get the structure the way you want it.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now