Solved

Count values in a query

Posted on 2012-12-27
7
330 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 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

751 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