Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Friends, the table Employee's structure is EmpId Int32, Date DateTime and Expenditure decimal(18,2). Here I store employees' expenditure date wise. The problem is that I need to sum up the expenditure month wise for every employee and show it in control like Grid View/Details view in the following format:

EmpId Month TotalExpenditure

Please help me out.
Thanks
Posted

 
Share this answer
 
Comments
Espen Harlinn 24-Jun-12 10:28am    
Going from there to a solution should be pretty easy :-)
Sandeep Mewara 24-Jun-12 15:39pm    
Thanks Espen.
Brajabas 24-Jun-12 14:00pm    
Thanks Sandeep
Sandeep Mewara 24-Jun-12 15:00pm    
Welcome.
you need to create a stored proc for doing this.
before you need to get starting date and end date of the month. from the front end using code.

create proc prcTotal(@ImpId int, @sDate datetime, @eDate datetime)
on tbl_name
as
(
Declare @total int,
Declare @month varchar(20),
Select @total = sum(Expenditure) from tbl_name where date_col=@sDate between Date_col=@eDate
Select EmpId, 'Month'= case
when 'Condition for month' then 'January',
when 'Condition for month' then 'February',
when 'Condition for month' then 'March',
when 'Condition for month' then 'April',
when 'Condition for month' then 'May',
when 'Condition for month' then 'June',
when 'Condition for month' then 'July',
when 'Condition for month' then 'August',
when 'Condition for month' then 'September',
when 'Condition for month' then 'October',
when 'Condition for month' then 'November',
when 'Condition for month' then 'December',
'MonthExpenditure'=@total where EmpId=@EmpId and Date_col=@sDate and Date_col=@eDate
)

try this.
 
Share this answer
 
Comments
Brajabas 24-Jun-12 14:00pm    
Thanks Shiv
The query should be similar to the following..


SQL
SELECT EmpID
       , DATENAME(Month, cast( Date as datetimeoffset)) as  Month
       , sum(Expenditure) as TotalExpenditure
      
FROM Employee
GROUP BY EmpID, DATENAME(Month, cast( Date as datetimeoffset))
 
Share this answer
 
Comments
Brajabas 24-Jun-12 14:01pm    
Thanks SalCon

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