Solved

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

Posted on 2012-03-13
7
334 Views
Last Modified: 2012-03-13
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!
0
Comment
Question by:SeyerIT
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
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));
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try replacing "Expression" with "Last" or "First"
0
 
LVL 2

Author Comment

by:SeyerIT
Comment Utility
Runrigger, I tried your sql and am getting the following error;
Capricorn, I also tried your method and got the same error.
error
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Accepted Solution

by:
Runrigger earned 500 total points
Comment Utility
Try this.

SELECT Sum(dbo_View_LaborDtl.ldLaborHrs) AS SumOfldLaborHrs,
Sum(dbo_View_LaborDtl.ldEarnedHrs) AS SumOfldEarnedHrs,
Sum(IIf([ldLaborRate]=0,[ebLaborRate],[ldLaborRate])) AS AdjLaborRate,
Round16(Sum([ldLaborHrs]*IIf([ldLaborRate]=0,[ebLaborRate],[ldLaborRate])),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));
0
 
LVL 2

Author Closing Comment

by:SeyerIT
Comment Utility
That works! Thanks for the help!
0
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
a pleasure, and thanks for the points
0
 
LVL 2

Author Comment

by:SeyerIT
Comment Utility
No problem!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now