Case expression As Columns
16:29 20 Aug 2020

I have the following Case expression which I would like to display as columns values in the output so the result set is formatted like this:

Resultset Header

SELECT 
    l.Title as List
,   CASE 
        WHEN _Custom57 between 13 and 17 THEN '13-17' 
        WHEN _Custom57 between 18 and 24 THEN '18-24' 
        WHEN _Custom57 between 25 and 34 THEN '25-34' 
        WHEN _Custom57 between 35 and 44 THEN '35-44' 
        WHEN _Custom57 between 45 and 54 THEN '45-54' 
        WHEN _Custom57 >= 55 THEN '55-64' 
        WHEN _Custom57 >= 65 THEN '65+' 
    END as Age
,   COUNT(r.ID) as RecipCount
FROM mytable (NOLOCK)
sql sql-server case