Solved

Need help with Access Query

Posted on 2014-07-25
6
299 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
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 35

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 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