Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am doing a c# project i working with visual studio and i have a winform in that there is two combobox the first is of month and second is of year and a button by the side. and i have a table. in that table there is two column named "date" which is having datatype smalldatetime. and another is "price" which is varchar when the button is clicked i want that according to the month and year it checkes the table and display the total sum of the column of price in a label. is that possible to do? i am not using any datagrid or anything dataview such type. i am using a label to display can i calculate and show the sum?
Posted

1 solution

Following query may help

SQL
select sum(price)
from yourtable
where
datepart(mm,yourDateColumn)=yourMonthSelected
and
datepart(yy,yourDateColumn)=yourYearSelected


Don't have SQL access at present, so check syntax, though logically thsi si correct

Hope that helps
Milind
 
Share this answer
 
Comments
Hemant Singh Rautela 15-Jan-13 9:12am    
datepart(), it returns numeric value

For Detail

http://msdn.microsoft.com/en-us/library/ms174420.aspx
MT_ 15-Jan-13 9:15am    
Yes Hemantrautela, it will return integer. OP hasn't made clear what heshe has got in the combobox though. But you can always convert in to number.
shaikh-adil 15-Jan-13 9:44am    
sir i am using entity framework. Then it will help? This query can be used to display sum in a label.text?
Hemant Singh Rautela 15-Jan-13 10:29am    
Why not try it yourself...

It is valid sql query & you get the sum of price. then you can use this value anywhere...
shaikh-adil 15-Jan-13 12:45pm    
sir your answer is correct (thank you really for helping me and newbies) can you further help me that can i count the total number of rows in that column? what i have to made changes?

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