SELECT
ISNULL((CASE WHEN [org].group= 'prod a1' THEN [org].sgroup WHEN [org].group= 'prod a2' THEN [org].sgroup
WHEN [org].group= 'prod a3' THEN [org].sgroup WHEN [org].group= 'prodource' THEN [org].sgroup
WHEN [org].group= 'legacy' THEN [org].sgroup WHEN [org].group= 'mapping' THEN [org].sgroup
ELSE [org].group END), 0) AS xyz,
sum(DATEDIFF(n, Enq.OpenDate, Enq.ClosedDate))as [Mins to close],count(*) as totalenqs
FROM
Team RIGHT OUTER JOIN
Org
INNER JOIN
Enq ON Org.Category = Enq.Category AND Org.Queue = Enq.OriginalQueue ON Team.[Rep ID] = Enq.ClosedBy
where Enq.closeddate >= @startdate and Enq.closeddate < @Enddate
and (Enq.EnqType_ID = '123456') AND (Team.Team = 1)
group by (ISNULL(CASE WHEN [org].group= 'prod a1' THEN [org].sgroup WHEN [org].group= 'prod a2' THEN [org].sgroup
WHEN [org].group= 'prod va3' THEN [org].sgroup WHEN [org].group= 'prodource' THEN [org].sgroup
WHEN [org].group= 'legacy' THEN [org].sgroup WHEN [org].group= 'mapping' THEN [org].sgroup
ELSE [org].groupEND), 0))
|