Link to home
Start Free TrialLog in
Avatar of Jeremy Campbell
Jeremy CampbellFlag for United States of America

asked on

Need help resolving aggregate function error in totals query in Access.

Here is the query I'm trying to run;
User generated image
Here is the sql;
SELECT Sum(dbo_View_LaborDtl.ldLaborHrs) AS SumOfldLaborHrs,
Sum(dbo_View_LaborDtl.ldEarnedHrs) AS SumOfldEarnedHrs,
IIf([ldLaborRate]=0,[ebLaborRate],[ldLaborRate]) AS AdjLaborRate,
Round16([ldLaborHrs]*[AdjLaborRate],2) AS ldAmount
FROM dbo_View_LaborDtl
LEFT JOIN dbo_View_EmpBasic
ON dbo_View_LaborDtl.ldEmployeeNum = dbo_View_EmpBasic.ebEmpId
WHERE (((dbo_View_LaborDtl.ldPayrollDate)>=Eval('[Forms]![frmCSLPL]![txtStartDate]')
And (dbo_View_LaborDtl.ldPayrollDate)<=Eval('[Forms]![frmCSLPL]![txtEndDate]'))
AND ((dbo_View_LaborDtl.ldLaborType)<>"I") AND ((dbo_View_LaborDtl.ldLaborHedSeq)<>0));


And here is the error I'm getting;

User generated image
Thanks in advance for the help!
Avatar of Runrigger
Runrigger
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this, basically, you are trying to sum two fields, but not sum the two remaining ones, I have made an assumption that you need to sum all 4 of the returned fields.

SELECT Sum(dbo_View_LaborDtl.ldLaborHrs) AS SumOfldLaborHrs,
Sum(dbo_View_LaborDtl.ldEarnedHrs) AS SumOfldEarnedHrs,
Sum(IIf([ldLaborRate]=0,[ebLaborRate],[ldLaborRate])) AS AdjLaborRate,
Sum(Round16([ldLaborHrs]*[AdjLaborRate],2)) AS ldAmount
FROM dbo_View_LaborDtl
LEFT JOIN dbo_View_EmpBasic
ON dbo_View_LaborDtl.ldEmployeeNum = dbo_View_EmpBasic.ebEmpId
WHERE (((dbo_View_LaborDtl.ldPayrollDate)>=Eval('[Forms]![frmCSLPL]![txtStartDate]')
And (dbo_View_LaborDtl.ldPayrollDate)<=Eval('[Forms]![frmCSLPL]![txtEndDate]'))
AND ((dbo_View_LaborDtl.ldLaborType)<>"I") AND ((dbo_View_LaborDtl.ldLaborHedSeq)<>0));
Avatar of Rey Obrero (Capricorn1)
try replacing "Expression" with "Last" or "First"
Avatar of Jeremy Campbell

ASKER

Runrigger, I tried your sql and am getting the following error;
Capricorn, I also tried your method and got the same error.
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Runrigger
Runrigger
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That works! Thanks for the help!
a pleasure, and thanks for the points
No problem!