Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
Pls help me thanks in advance
error is:- Invalid use of group function
public DataTable Search(int accountid, DateTime start, DateTime end,decimal amount)
            string qry = "select * from Account where date >=@start and date <=@end and accountid=@accountid and sum(amount)=@amount";
            MySqlParameter startP = new MySqlParameter("@start", start);
            MySqlParameter endP = new MySqlParameter("@end", end);
            MySqlParameter accountidP = new MySqlParameter("@accountid", accountid);
            MySqlParameter amountP=new MySqlParameter("@amount",amount);
            MySqlParameter[] p = { startP, endP, accountidP, amountP };
            return MySqlHelper.ExecuteDataset(Common.GetConnectionString(), qry, p).Tables[0];
            Exception ex = new Exception(" Search AccountDetail Error.");
            throw ex;
Posted 12-Dec-12 17:42pm
jibesh at 13-Dec-12 0:04am
This is already posted here. Please do not create duplicate questions unless they have different nature. Close this and you will get the reply of what ever questions you asked in other thread when any member finds a solution that suits to you.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are going to use aggregate function "Sum" but you did not use group by.
That's why the error occur.
For complete reference :[^]
but in your case I think sub query will helpful, or inline grouping Smile | :)
pankajgarg1986 at 13-Dec-12 0:43am
this query is also not working string qry = "select * from parmarth where date >=@start and date <=@end and accountid=@accountid having sum(amount)<=@amount";
Suvabrata Roy at 13-Dec-12 0:46am
you did not use Group by string qry="select accountid,sum(amount) TotAmount from parmarth where date >=@start and date <=@end and accountid=@accountid Group By accountid having sum(amount)<=@amount"; Try this

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

  Print Answers RSS
Your Filters
0 Sergey Alexandrovich Kryukov 437
1 sanket saxena 355
2 thatraja 240
3 Abhinav S 216
4 CPallini 215
0 Sergey Alexandrovich Kryukov 8,784
1 OriginalGriff 5,025
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid