Solved

Need help with Access Query

Posted on 2014-07-25
6
304 Views
Last Modified: 2014-07-25
Experts, can you please help me with this. I need a query to produce the IDTPartNumber and Description from the Equipment Table. And then I need the sum of Qty from the SalesEquipment table for the IDTPartNumber. And I need to find these based on year. So SalesDate Between #1/1/2014# and #7/25/2014#.
Screen1.png
0
Comment
Question by:Basicfarmer
[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
6 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40219624
It looks as if there should be a many-to-many relationship here, with SalesEquipment as the junction table.  It would be best to set up this relationship, to ensure referential integrity.  Can you post the database (or a cut-down version of it)?  I would like to have the actual tables to work with, but it might be possible to just use the appropriate fields from all three tables in a query, or if that doesn't work, make a date-limited query based on the Sales table, and link that to the other two tables to get the fields you need.  Then either do a Sum on Qty in that table, or save that query as a select query, and make a totals query based on it to get the sum.
0
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40219632
Use the QBE to build the query.  It is a big help when you are unfamiliar with SQL syntax or just don't want to type it all out.

Add the three tables to the QBE.
Draw the join lines as indicated.
Select the desired fields.
Press the big sigma button to make this a Totals query.
Change "group by" to Sum for the Qty field
Add Between #1/1/2014# and #7/25/2014# to the criteria cell for the SalesDate column
Change "group by"  to Where for the SalesDate column (if you don't do this, you'll get a sum for each day in the range rather than a sum for the whole range.

PS - my personal preference is to NEVER use "ID" as the name of the primary key.  I suggest always using a meaningful name.
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 40219644
SELECT
   e.IDTPartNumber
   ,MAX(e.Description) [Part Description]
   ,SUM(se.QTY) [Total Quantity]
FROM
  Equipment e
JOIN
  SalesEquioment se
         ON se.EquipmentID = e.ID
JOIN
   Sales s
       ON s.ID = se.SaleID
WHERE s. SalesDate Between #1/1/2014# and #7/25/2014#
GROUP BY
e.IDTPartNumber
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40219653
try this query

SELECT Sales.SalesDate, Equipment.IDTPartNumber
FROM (Sales INNER JOIN SalesEquipment ON Sales.ID = SalesEquipment.SaleID) INNER JOIN Equipment ON SalesEquipment.EquipmentID = Equipment.ID
WHERE Sales.SalesDate Between #1/1/2014# And #7/25/2014#
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40219657
oops, sorry i did not see the SUM part...
0
 

Author Closing Comment

by:Basicfarmer
ID: 40219759
Perfect Instructions Thanks. I got errors on the other suggested solutions.
0

Featured Post

Technology Partners: 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

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…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

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