Thursday, August 28, 2014

4 Select Queries into one statement


WITH cte AS(
SELECT
CASE
WHEN [Episode Start] BETWEEN '2014-06-01' AND '2014-06-30' THEN 'Starts'
WHEN [Episode Start] BETWEEN '2014-06-01' AND '2014-06-30' AND [Start Type Desc]='Continuing/Conversion' THEN 'Conversions'
WHEN [Episode End] BETWEEN '2014-06-01' AND '2014-06-30' THEN 'Achievements'
WHEN [Expected End]>=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) AND [Expected End]<DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0) THEN 'OutofFunding '
ELSE ''
END as Cat
FROM [dbo].[NEWVIEW]
WHERE [Cohort Desc] IN ('SSW')
)
SELECT
Cat
,COUNT(*) as total
FROM cte
GROUP BY Cat






No comments:

Post a Comment