Solved

Count values in a query

Posted on 2012-12-27
7
341 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
[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
  • 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 48

Expert Comment

by:Dale Fye
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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 48

Accepted Solution

by:
Dale Fye 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 48

Expert Comment

by:Dale Fye
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 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