Best way to sum up a field to a given day

GBalcom

Much to learn!
Local time
Today, 01:24
Joined
Jun 7, 2012
Messages
462
I have a situation where I'd like to look up a query that has a date field, along with an estimated hours field. This query may represent 20-100 records. I'd like to sum them up the estimated hours by date, then loop through the sums in a recordset. If the sum for a given day exceeds X, I want to send an email notifying someone of the conflict.

I'm having a hard time wrapping my head around the most efficient way to do get the sums. If it helps, below is the SQL for the base query.

Code:
SELECT DBA_WO.TargetFinDt, DBA_WO.EstHrs
FROM DBA_WO
WHERE (((DBA_WO.TargetFinDt)>Date()) AND ((DBA_WO.WorkOrdStatusNbr)<5))
ORDER BY DBA_WO.TargetFinDt;

I'll try to attach the results. When I try to sum up the EstHrs field per day, it seems to pull in results that should be filtered out by the "WorkOrdStatusNbr>5"

Thanks for any insight.
 

Attachments

  • query results.PNG
    query results.PNG
    20.3 KB · Views: 127
Try opening a recordset on

SELECT TargetFinDt, Sum(EstHrs) AS TotalHours FROM QueryName GROUP BY TargetFinDt
 
Thanks Paul!
 
No problemo! By the way, if you only care about sums over x:

SELECT TargetFinDt, Sum(EstHrs) AS TotalHours
FROM QueryName
GROUP BY TargetFinDt
HAVING Sum(EstHrs) > x
 

Users who are viewing this thread

Back
Top Bottom