Click here to Skip to main content
15,915,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Am new to programming, i build an application for a store in visual studio using c# and crystal report for report generation. but i have a problem withe the report, i have a query that i use to fetch data from my sql database and display it on my crystal report but some data field are not showing. but if i write the query without using the group by it will show. below is the query

C#
"select Itemname, SUM(QntSold), SUM(TotalAmnt) from POS  where Date ='" + Convert.ToDateTime(date) + "'GROUP BY Itemname";


with the above query it will only show the group itemnames and will not show the other two table fields which are QntySoild and TotalAmnt. But if i write this other query it will show all the table fields but will not group the itemname, below is the other query that display all but not in group format.

C#
"select * from POS where date ='" + Convert.ToDateTime(date) + "'";



Plz is anything am doing wrong that is not making it to show other fields when it is been grouped because i want it to be grouped together
Thank you

What I have tried:

"select Itemname, SUM(QntSold), SUM(TotalAmnt) from POS where Date ='" + Convert.ToDateTime(date) + "'GROUP BY Itemname";
Posted
Updated 10-Jun-16 19:20pm

When you apply aggregate functions like SUM() you lose the column name. So you need to give it a name just like the non-aggregated result columns.

try

SQL
select Itemname, SUM(QntSold) AS QntSold, SUM(TotalAmnt) as TotalAmnt from POS where Date ='" + Convert.ToDateTime(date) + "'GROUP BY Itemname"; 
 
Share this answer
 
Comments
Member 12414126 11-Jun-16 1:21am    
Thank you Mnaught, both field works fine now and they are both showing on my crystal report but I noticed the date is not showing in date field which I make as the header of the report, what can I do to also make the date to Show. Thank you in advance
Thank you Mnaught, both field works fine now and they are both showing on my crystal report but I noticed the date is not showing in date field which I make as the header of the report, what can I do to also make the date to Show. Thank you in advance
 
Share this answer
 

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