Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pls help me thanks in advance
error is:- Invalid use of group function
C#
public DataTable Search(int accountid, DateTime start, DateTime end,decimal amount)
    {
        try
        {
            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];
        }
        catch
        {
            Exception ex = new Exception(" Search AccountDetail Error.");
            throw ex;
        }
Posted
Comments
Jibesh 13-Dec-12 0:04am    
This is already posted here.
http://www.codeproject.com/Questions/508033/InplusAccountplusSoftwareplusSelectplusAmountplusb

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

Hi,

You are going to use aggregate function "Sum" but you did not use group by.
That's why the error occur.

For complete reference : http://msdn.microsoft.com/en-us/library/aa258901(v=sql.80).aspx[^]

but in your case I think sub query will helpful, or inline grouping :)
 
Share this answer
 
Comments
pankajgarg1986 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 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)



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