Click here to Skip to main content
15,357,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While I am running the query, its showing like below error

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

What I have tried:

DataFilterCondition = " Where pi.pledgedate >= @Me.dtpAccountFrom.Value.Date And pi.pledgedate <= @Me.dtpAccountTo.Value.Date And p.redeemed = 1 "


DataFilterQuery = "Select pi.itemname, pi.goldweight, pi.stoneweight, pi.nos " & _
            "From (pledgeritem pi Inner Join pledger p On pi.pledgeno = p.pledgeno) " & DataFilterCondition & " Group By pi.itemname Order By pi.itemname"
Posted
Updated 25-Sep-20 20:43pm

See here: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]
The error message is different in Access, but the reason is the same.
   
Comments
Maciej Los 26-Sep-20 3:36am
   
5ed!
At the moment you don't do any aggregation at all so GROUP BY clause seems unnecessary. Either remove it
DataFilterQuery = "Select pi.itemname, pi.goldweight, pi.stoneweight, pi.nos " & _
            "From (pledgeritem pi Inner Join pledger p On pi.pledgeno = p.pledgeno) " & DataFilterCondition & " Order By pi.itemname"

or add desired aggregations in the statement, for example something like
DataFilterQuery = "Select pi.itemname, sum(pi.goldweight), sum(pi.stoneweight), sum(pi.nos) " & _
            "From (pledgeritem pi Inner Join pledger p On pi.pledgeno = p.pledgeno) " & DataFilterCondition & " Group By pi.itemname Order By pi.itemname"
   
Comments
Maciej Los 26-Sep-20 3:36am
   
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900