Avatar of Jeremy Campbell
Jeremy Campbell
Flag 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;
query
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;

error
Thanks in advance for the help!
Microsoft Access

Avatar of undefined
Last Comment
Jeremy Campbell

8/22/2022 - Mon
Runrigger

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));
Rey Obrero (Capricorn1)

try replacing "Expression" with "Last" or "First"
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.
error
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Runrigger

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jeremy Campbell

ASKER
That works! Thanks for the help!
Runrigger

a pleasure, and thanks for the points
Jeremy Campbell

ASKER
No problem!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.