query to group by month

Experts,
Here's my objective. To create a query where I sum quantity scrapped for each month by part number and line code. I got this far

SELECT tblScrapTicket.ScrapTicketDate, tblLineCode.LineCodeNumber, tblLineCode.LineCodeDescription, tblPartNumber.PartNumber, tblPartNumber.PartNumberDescription, tblScrapTicket.QuantityScrapped
FROM tblPartNumber INNER JOIN (tblScrapTicket INNER JOIN tblLineCode ON tblScrapTicket.LineCodeID = tblLineCode.LineCodeID) ON tblPartNumber.PartNumberID = tblScrapTicket.PartNumberID
WHERE (((tblScrapTicket.ScrapTicketDate) Between [Beginning Date] And [Ending Date]))
ORDER BY tblPartNumber.PartNumber;

Frank FreeseAsked:
Who is Participating?
 
Shanmuga SundaramConnect With a Mentor Director of Software EngineeringCommented:
sorry it should be as given below.

SELECT Format(tblScrapTicket.ScrapTicketDate, "YY.MM"),tblLineCode.LineCodeNumber, tblLineCode.LineCodeDescription, tblPartNumber.PartNumber, tblPartNumber.PartNumberDescription, sum(tblScrapTicket.QuantityScrapped)
FROM tblPartNumber INNER JOIN (tblScrapTicket INNER JOIN tblLineCode ON tblScrapTicket.LineCodeID = tblLineCode.LineCodeID) ON tblPartNumber.PartNumberID = tblScrapTicket.PartNumberID
WHERE (((tblScrapTicket.ScrapTicketDate) Between [Beginning Date] And [Ending Date]))
groub by Format(tblScrapTicket.ScrapTicketDate, "YY.MM"),tblLineCode.LineCodeNumber, tblLineCode.LineCodeDescription, tblPartNumber.PartNumber, tblPartNumber.PartNumberDescription
ORDER BY tblPartNumber.PartNumber;
0
 
tomasgruenerCommented:
I would add a group by clause, which groups for the year and the month.
I'm not very used to access sql syntax, but I think you have to add following line befor the ORDER BY Clause

GROUP Format(tblScrapTicket.ScrapTicketDate, "YY.MM")
(include the year in the group clause, so you can group correctly, even if you group over several years)
0
 
Shanmuga SundaramDirector of Software EngineeringCommented:
check whether this helps

SELECT Format(tblScrapTicket.ScrapTicketDate, "YY.MM")tblLineCode.LineCodeNumber, tblLineCode.LineCodeDescription, tblPartNumber.PartNumber, tblPartNumber.PartNumberDescription, sum(tblScrapTicket.QuantityScrapped)
FROM tblPartNumber INNER JOIN (tblScrapTicket INNER JOIN tblLineCode ON tblScrapTicket.LineCodeID = tblLineCode.LineCodeID) ON tblPartNumber.PartNumberID = tblScrapTicket.PartNumberID
WHERE (((tblScrapTicket.ScrapTicketDate) Between [Beginning Date] And [Ending Date]))
groub by Format(tblScrapTicket.ScrapTicketDate, "YY.MM")tblLineCode.LineCodeNumber, tblLineCode.LineCodeDescription, tblPartNumber.PartNumber, tblPartNumber.PartNumberDescription
ORDER BY tblPartNumber.PartNumber;
0
 
Frank FreeseAuthor Commented:
thanks...it looks like it'll get me where i need. just had to change groub to group
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.