Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with Access Query

Posted on 2014-07-25
6
Medium Priority
?
311 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 40

Accepted Solution

by:
PatHartman earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

782 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