Click here to Skip to main content
15,887,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form in which i have a two dropdown one for "From Year" and other for
"To Year", when the user select the "from year" e.g 2000 and "To Year" e.g 2005, then i want report like this
i have a table named FileRegister with fields id,title,fileno,daterecieving and current status, in current status i save four values open,close,pending and Inprogress.i know that year can be found from daterecieving,but for multiple year like this i have no idea.
Year           open      close      pending         inprogress      total
2000           1          3          4                 5            13
2001
2002
2003
2004
2005

From this query i can select the current status different values.
SQL
SELECT 
SUM( case current_status when 'Open' then 1 else 0 end ) as 'Open',
SUM( case current_status when 'Close' then 1 else 0 end ) as 'Closed',
SUM( case current_status when 'Pending' then 1 else 0 end ) as 'Pending',
SUM( case current_status when 'In Progress' then 1 else 0 end ) as 'InProgress',
SUM(1) as 'Total' from FileRegister

kindly help me.
Posted
Updated 26-Feb-12 20:12pm
v2
Comments
bilawal121 27-Feb-12 1:50am    
SELECT YEAR (DATE_RECIEVING) As [Yearnumber],
SUM( case current_status when 'Open' then 1 else 0 end ) as 'Open',
SUM( case current_status when 'Close' then 1 else 0 end ) as 'Closed',
SUM( case current_status when 'Pending' then 1 else 0 end ) as 'Pending',
SUM( case current_status when 'In Progress' then 1 else 0 end ) as 'InProgress',
SUM(1) as 'Total' from FileRegister group by YEAR(date_recieving)

this give me the result for one year like 2012 but i want as i mentioned

1 solution

Yes i have solve this my self thanks for those who spend there time to read my post
SQL
SELECT YEAR (DATE_RECIEVING)  As [Yearnumber],
SUM( case current_status when 'Open' then 1 else 0 end ) as 'Open',
SUM( case current_status when 'Close' then 1 else 0 end ) as 'Closed',
SUM( case current_status when 'Pending' then 1 else 0 end ) as 'Pending',
SUM( case current_status when 'In Progress' then 1 else 0 end ) as 'InProgress',
SUM(1) as 'Total' from FileRegister 
where YEAR(DATE_RECIEVING)>='2001' and YEAR(DATE_RECIEVING)<='2014' 
group by YEAR(date_recieving)

in 2001 and 2014 you can replace your parameters of store procedure as i did in my application :)
 
Share this answer
 
v2

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