Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Creating Closure rates By Months

$
0
0

Hi

I have created two queries, One is for total Open cases and other is total closed cases. I want to get the closure rate by month and the formula is TotalClosed/TotalOpen*100

TotalClosed

SELECT 
				Count(CaseReference) as TotalClosed,
				DateName( month , DateAdd( month , mONTH(ch.CaseCompletionDate) , -1 ) ) AS 'Month Name',
				Month(ch.CaseCompletionDate) as MonthNo
			From CaseHeader CH
					JOIN LookupItem LI2
						ON LI2.LookupItemId = CH.CaseStateLKId
						AND LI2.IsDeleted = 0
					JOIN LookupItem LI3
						ON LI3.LookupItemId = CH.CaseStageLKId	
						AND LI3.IsDeleted = 0
					JOIN CaseUser CU
							ON CH.CaseHeaderId = CU.CaseHeaderId
							AND CU.AssignedDate =
												(SELECT		Max(CU.AssignedDate)
												 FROM		CaseUser CU		
												 WHERE		CU.IsDeleted = 0
												 AND		CU.CaseHeaderId = CH.CaseHeaderId
												 AND		CU.CaseRoleTypeLKId = 'fd843c4e-093b-4eeb-adf3-18903a0c46dd')
					JOIN UserDetail 
							ON CU.UserDetailId = UserDetail.UserDetailId
							AND CU.IsDeleted = 0	

					where YEAR(ch.CaseCompletionDate) = 2013 -- selection by the user 
					and ch.CaseCompletionDate is not null
					and ch.isdeleted = 0
					and LI3.ItemName in ('Screening', 'In the form required') Group by Month(CaseCompletionDate)

Total Open

SELECT 
				COUNT(CaseReference) AS TotalOpen,
				DateName( month , DateAdd( month , mONTH(ch.CaseCreationDate) , -1 ) ) AS 'Month Name',
				Month(ch.CaseCreationDate) as MonthNo
			From CaseHeader CH
					JOIN LookupItem LI2
						ON LI2.LookupItemId = CH.CaseStateLKId
						AND LI2.IsDeleted = 0
					JOIN LookupItem LI3
						ON LI3.LookupItemId = CH.CaseStageLKId	
						AND LI3.IsDeleted = 0
					JOIN CaseUser CU
							ON CH.CaseHeaderId = CU.CaseHeaderId
							AND CU.AssignedDate =
												(SELECT		Max(CU.AssignedDate)
												 FROM		CaseUser CU		
												 WHERE		CU.IsDeleted = 0
												 AND		CU.CaseHeaderId = CH.CaseHeaderId
												 AND		CU.CaseRoleTypeLKId = 'fd843c4e-093b-4eeb-adf3-18903a0c46dd')
					JOIN UserDetail 
							ON CU.UserDetailId = UserDetail.UserDetailId
							AND CU.IsDeleted = 0	

					where YEAR(ch.CaseCreationDate) = 2013 -- selection by the user 
					and ch.CaseCompletionDate is null
					and ch.isdeleted = 0
					and LI3.ItemName not like 'Restor%' Group by Month(ch.CaseCreationDate)

Results

How can I achive the following result using PIVOT?

MonthName ClosureRate

Jan10%

so on.

Many thanks,

MH


MH


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>