Q:

using case statement to assign columnnames

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.

A:

This is what I meant
CASE WHEN PRIORITY='1' then  (ID)   END as 'BlockerIn',
CASE WHEN PRIORITY='2' then  (ID)  END  as 'CriticalOut'

This would create two columns with the values in.
If you want one column with multiple values you would do
CASE WHEN PRIORITY='1' then  'BlockerIn' 
WHEN PRIORITY='2' then  'CriticalOut' END  AS Priority

