Query to add totals

D

Duane Hookom

You need to understand how to create queries and use various expressions. You
can create queries with LEFT or RIGHT JOINs that include all the records from
one table and matching from the other.

--
Duane Hookom
Microsoft Access MVP


jenksonu via AccessMonster.com said:
This still doesn't seem to work... So I back tracked in our conversation and
changed the YTD code you gave me to look like this.
SELECT [EmployeeName], Sum([HoursWorked]) AS MTD
FROM test
WHERE Month(TheDate)=Month(Date())
GROUP BY [EmployeeName];
Then I did a new query that joined the MTD and YTD that looks like this
SELECT MTD.EmployeeName, MTD.MTD, YTD_2009.YTD_2009
FROM MTD INNER JOIN YTD_2009 ON MTD.EmployeeName = YTD_2009.EmployeeName;
This seems to work for what I need.
One question, I have noted that if there is no data for this month, then this
query MTD and YTD shows no user names and or YTD Information. Is there a way
to make MTD show all 0 if no entry's for the current month?

Duane said:
Try:

SELECT EmployeeName,
Sum(HoursWorked * Abs(Format(TheDate,"yyyymm") =
Format(Date(),"yyyymm"))) as MTD,
Sum(HoursWorked * Abs(Year(TheDate) = Year(Date())) ) as YTD
FROM testQuery
GROUP BY EmployeeName;
I still can't seen to get this to work. Still getting Syntax error (Missing
Operator)
[quoted text clipped - 28 lines]
each Month
Thanks in advance for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top