My Assistant
![]() ![]() |
|
|
May 5 2006, 11:52 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 188 |
I'm using a SQL Statement (query builder) in a report. Now I'm trying to get the query right before I can really use the report to print what I need. I divided up a shipping date into two columns, M: Month([Date]), and Y: Year([Date]). And I use a Criteria in both columns to ask for a month number and year. I'm getting part of the results I want. However, I can't seem to figure out how to combine all items shipped into one Summary. It will display the results for an item per each month going back to the first month items were shipped to a customer. I do have a Group By "Sum" on the Quantities. I really need to just show the total for all items at one time, not by each month. Can anyone help me? If I can figure this out, I will be set!
|
|
|
|
May 5 2006, 12:28 PM
Post
#2
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
Date is a reserved word in Access. Continued use will cause problems in the future.
Select Format(YourDate,"yyyymm") as ReportMonth, Customer, Sum(Quantities) as Quantities From YourTable Group By Format(YourDate,"yyyymm") , Customer Order By Format(YourDate,"yyyymm") , Customer |
|
|
|
May 5 2006, 12:44 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 188 |
Here's my written query SQL Statement:
SELECT Jobsites.JobsiteID, Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, Sum(tblOrderDetails.Quantity) AS SumOfQuantity, tblItems.ItemType, Month([Date]) AS Expr1 FROM (Jobsites INNER JOIN tblOrders ON Jobsites.JobsiteID = tblOrders.JobsiteID) INNER JOIN (tblOrderDetails INNER JOIN tblItems ON (tblOrderDetails.Category = tblItems.Category) AND (tblOrderDetails.Description = tblItems.Description)) ON tblOrders.TicketID = tblOrderDetails.TicketID GROUP BY Jobsites.JobsiteID, Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, tblItems.ItemType, Month([Date]) HAVING (((Jobsites.JobsiteID)=[Enter JobsiteID]) AND ((tblItems.ItemType)="R") AND ((Month([Date]))<[Enter Month Number])); This gives a better idea as to what I have going on. |
|
|
|
May 5 2006, 12:52 PM
Post
#4
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
CODE SELECT Jobsites.JobsiteID,
Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, Sum(tblOrderDetails.Quantity) AS Quantity, tblItems.ItemType, Format([Date],"yyyymm") AS Expr1 FROM (Jobsites INNER JOIN tblOrders ON Jobsites.JobsiteID = tblOrders.JobsiteID) INNER JOIN (tblOrderDetails INNER JOIN tblItems ON (tblOrderDetails.Category = tblItems.Category) AND (tblOrderDetails.Description = tblItems.Description)) ON tblOrders.TicketID = tblOrderDetails.TicketID WHERE Jobsites.JobsiteID=[Enter JobsiteID] AND tblItems.ItemType="R" AND Format([Date],"yyyymm")<[Enter YYYYMM] GROUP BY Jobsites.JobsiteID, Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, tblItems.ItemType, Format([Date],"yyyymm"); |
|
|
|
May 5 2006, 01:09 PM
Post
#5
|
|
|
UtterAccess Addict Posts: 188 |
I appreciate that help, however, I'm still back to square one. It's returning results that divides up the sum of the quantities by month. I want the total over all the months up to the month and year I enter into the parameter. Any suggestions?
|
|
|
|
May 5 2006, 01:21 PM
Post
#6
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
CODE SELECT Jobsites.JobsiteID,
Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, Sum(tblOrderDetails.Quantity) AS Quantity, tblItems.ItemType FROM (Jobsites INNER JOIN tblOrders ON Jobsites.JobsiteID = tblOrders.JobsiteID) INNER JOIN (tblOrderDetails INNER JOIN tblItems ON (tblOrderDetails.Category = tblItems.Category) AND (tblOrderDetails.Description = tblItems.Description)) ON tblOrders.TicketID = tblOrderDetails.TicketID WHERE Jobsites.JobsiteID=[Enter JobsiteID] AND tblItems.ItemType="R" AND [Date] <= [Enter Date] GROUP BY Jobsites.JobsiteID, Jobsites.JobsiteName, tblOrderDetails.Category, tblOrderDetails.Description, tblItems.ItemType; |
|
|
|
May 5 2006, 01:56 PM
Post
#7
|
|
|
UtterAccess Addict Posts: 188 |
Hey, that's working great! Now, I need to multiply the Quantity times a RentalRate that I added to the SQL Statement. It's not working right when I just enter ItemTotals: [Quantity]*[RentalRate]
|
|
|
|
May 5 2006, 01:59 PM
Post
#8
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
ItemTotals: Sum(tblOrderDetails.Quantity)*[RentalRate]
|
|
|
|
May 5 2006, 02:01 PM
Post
#9
|
|
|
UtterAccess Addict Posts: 188 |
Wait, I did something before you responded and it works now...Man, I really do appreciate your help. It's the small stuff that throwing me off. I think my employer will be sending me to some Access Training sometime soon so I won't be on UtterAccess ALL the time. I really have learned a lot from this website though. Much Thanks!!!
|
|
|
|
May 5 2006, 02:15 PM
Post
#10
|
|
|
UtterAccess Addict Posts: 188 |
Wait! Don't leave yet...another question. Need to show the date that I enter on the report in a textbox somewhere. How can I get that date that I enter in the parameter box on the report?
|
|
|
|
May 8 2006, 09:24 AM
Post
#11
|
|
|
UtterAccess Addict Posts: 188 |
Anybody know how to get an unbound text box to dislpay a date that is entered into a parameter. In my SQL statement behind my report I have [Date] <= [Enter Date] under a "Where" Group By. I would like the Date I enter in the parameter box to display on my report. Need a little help here...
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 19th June 2013 - 06:55 PM |