Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aggregate function error message

Status
Not open for further replies.

cheyenne2002

Instructor
Joined
Jul 26, 2005
Messages
229
Location
US
I have the following code behind my query and I keep getting a strange error.
====code====
SELECT tLots.PropertyNo, tLots.SubDivision, tLots.County, tLots.ST, tLots.PID, tLots.LegDesc, tLots.[Market$], tTaxPaid.TaxPaid, tTaxPaid.TaxDue, tTaxPaid.TaxYear, Sum([tTaxPaid]![TaxPaid]) AS TotalTax
FROM tLots INNER JOIN tTaxPaid ON tLots.PropertyNo = tTaxPaid.PropertyNo
WHERE (((tTaxPaid.TaxDue)=Yes) AND ((tTaxPaid.TaxYear)=[Enter Tax Year]));

---Error----
You tried to execute a query that does not include the specified expression 'ProperyNo' as part of an aggregate function.

----

Can anyone explain what the error is trying to tell me. I do have the PropertyNo as part of the query.

PS: I created the query using Access and not directly with SQL as I am really shakey with SQL coding.

Sami
 
You need to rewrite your query with a Group By clause like this:

Code:
SELECT 
    tLots.PropertyNo, 
    tLots.SubDivision, 
    tLots.County, 
    tLots.ST, 
    tLots.PID, 
    tLots.LegDesc, 
    tLots.[Market$], 
    tTaxPaid.TaxPaid, 
    tTaxPaid.TaxDue, 
    tTaxPaid.TaxYear, 
    Sum([tTaxPaid]![TaxPaid]) AS TotalTax
FROM 
    tLots 
    INNER JOIN tTaxPaid ON tLots.PropertyNo = tTaxPaid.PropertyNo
WHERE 
    (((tTaxPaid.TaxDue)=Yes) 
    AND ((tTaxPaid.TaxYear)=[Enter Tax Year]))
Group by
    tLots.PropertyNo, 
    tLots.SubDivision, 
    tLots.County, tLots.ST, 
    tLots.PID, tLots.LegDesc, 
    tLots.[Market$], 
    tTaxPaid.TaxPaid, 
    tTaxPaid.TaxDue, 
    tTaxPaid.TaxYear;

This is because you have the Sum function and are doing a summary.
 
Now it works
Really ? Isn't TotalTax the same as TaxPaid in ALL rows ?
 
PHV is correct. You don't want to have TaxPaid!TaxPaid, if you are summing it as well, because then you will not be getting a sum, you will be getting taxpaid on each row.

Good catch PHV. I did not see that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top