I have a script and need to have the counts for A.AssociateID (to get the total emp count per dept) and vComply (which has three outputs, 'Compliant', 'Non-Compliant', 'Current'), grouped by dept.
So, the outputs I want are:
DEPT EMP_COUNT Compliant Current Non-Compliant
1S 44 12 17 15
1N 15 7 3 4
2A 21 16 ...................
..........
Please advise.
Thanks so much.
select
A.Dept,
CASE
WHEN
ANNUADateRespFCGiven BETWEEN '10/01/2008' and '12/31/2008'
and DATENAME(m,ANNUADateRespFCGiven) = RespFCMonth
and ANNUADateRespFCGiven BETWEEN DateAdd(mm,DateDiff(m,0,'2008-10-01 00:00:00'),-31)
AND DateAdd(mm,DateDiff(m,-1,'2008-12-31 23:59:59'),30)
THEN 'Compliant'
WHEN
ANNUADateRespFCGiven BETWEEN '10/01/2008' and '12/31/2008'
and DATENAME(m,ANNUADateRespFCGiven) != RespFCMonth
THEN 'Current'
ELSE 'Non-compliant'
END AS vComply
from AssociatePersonal A, MedicalINFO M
where A.AssociateID = M.AssociateID
and A.HireStatus not in ('Terminated Associates - Final', 'Term', 'Terminated Associates - Pending')
and M.RespirtoryResult not in ('Deferred', 'Exempt', 'Fail')
and CONVERT(VARBINARY, A.lname) = CONVERT(VARBINARY, UPPER(A.lname))
and A.Dept !=''
order by dept
So, the outputs I want are:
DEPT EMP_COUNT Compliant Current Non-Compliant
1S 44 12 17 15
1N 15 7 3 4
2A 21 16 ...................
..........
Please advise.
Thanks so much.
select
A.Dept,
CASE
WHEN
ANNUADateRespFCGiven BETWEEN '10/01/2008' and '12/31/2008'
and DATENAME(m,ANNUADateRespFCGiven) = RespFCMonth
and ANNUADateRespFCGiven BETWEEN DateAdd(mm,DateDiff(m,0,'2008-10-01 00:00:00'),-31)
AND DateAdd(mm,DateDiff(m,-1,'2008-12-31 23:59:59'),30)
THEN 'Compliant'
WHEN
ANNUADateRespFCGiven BETWEEN '10/01/2008' and '12/31/2008'
and DATENAME(m,ANNUADateRespFCGiven) != RespFCMonth
THEN 'Current'
ELSE 'Non-compliant'
END AS vComply
from AssociatePersonal A, MedicalINFO M
where A.AssociateID = M.AssociateID
and A.HireStatus not in ('Terminated Associates - Final', 'Term', 'Terminated Associates - Pending')
and M.RespirtoryResult not in ('Deferred', 'Exempt', 'Fail')
and CONVERT(VARBINARY, A.lname) = CONVERT(VARBINARY, UPPER(A.lname))
and A.Dept !=''
order by dept