Click here to Skip to main content
15,896,063 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 yeaer and other for month, when the user select the year e.g 2012 and month e.g january, 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.

open close pending inprogress total
Week1 1 3 4 5 13
Week2
Week3
Week4
Week5

kindly help me.
Posted

You can get the desired result by using a Pivot[^] query.
 
Share this answer
 
You try as the following -
SQL
Declare @year int
Declare @month int
Set @year=2012
Set @month=2

SELECT WeekNumber, [Open],[close],[pending],[inprogress]
FROM
(
Select DATEPART(DW,daterecieving  ) as WeekNumber, current_status,COunt(current_status) as StatusCount from FileRegister
Where DATEPART(YEAR,daterecieving )=@year AND DATEPART(M,daterecieving) =@month GROUP BY DATEPART(DW,daterecieving  ), current_status
) SourceTable
PIVOT
(
COunt(current_status)
FOR current_status IN
( [Open],[close],[pending],[inprogress] )) as OutputTable
Order by OutputTable.WeekNumber
 
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