Solved

Need help with Access Query

Posted on 2014-07-25
6
294 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
Comment Utility
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 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
oops, sorry i did not see the SUM part...
0
 

Author Closing Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now