I’m trying to re-write this as a case statement:
SELECT dateadd(day, -@Day, getdate()) AS Dt
,COUNT(pkey) AS 'BlockerOut'
FROM tablename
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
AND PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))>4) t1
JOIN
(SELECT dateadd(day, -@Day, getdate()) AS Dt
,COUNT(pkey) AS 'BlockerIn'
FROM jobissue
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
AND PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4) t2
ON t1.Dt = t2.Dt
I’ve gotten this far and can’t work out how to get further than column
SELECT dateadd(day, -@Day, getdate()) AS Dt,
CASE
WHEN PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4 then (pkey) end 'BlockerIn'
FROM [jobissue]
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
group by PRIORITY, CREATED, resolutiondate, pkey
this works.. but for two columns I get an error:
SELECT dateadd(day, -@Day, getdate()) AS Dt,
CASE
WHEN PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4 then (pkey) 'BlockerIn'
WHEN PRIORITY='2' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))>24 then (pkey) 'CriticalOut'
end
FROM jobissue
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
group by PRIORITY, CREATED, resolutiondate, pkey
Msg 102, Level 15, State 1, Line 18
Incorrect syntax near ‘BlockerIn’.
I can’t work out the syntax for more than one columnname.. help me please? Thanks.
This is what I meant
This would create two columns with the values in.
If you want one column with multiple values you would do