CASE expression with boolean operator
01:47 28 Jul 2017

See statement:

SELECT      t1.region, 
            Count(t1.orders) AS orders, 
            CASE t1.week 
                      WHEN < '5' THEN 'APR' 
                      WHEN < '10' THEN 'MAY' 
                      WHEN < '14' THEN 'JUN' 
                      WHEN < '19' THEN 'JUL' 
                      WHEN < '23' THEN 'AUG' 
                      WHEN < '27' THEN 'SEP' 
                      WHEN < '32' THEN 'OCT' 
                      WHEN < '36' THEN 'NOV' 
                      WHEN < '40' THEN 'DEC' 
                      WHEN < '45' THEN 'JAN' 
                      WHEN < '49' THEN 'FEB' 
                      WHEN < '53' THEN 'MAR' 
            END AS month, 
            dbo.inf_dates.months
            
FROM        dbo.[NonVoice Weekly_InflowCOMCAN] AS t1 
INNER JOIN  dbo.inf_dates 
                ON t1.week = dbo.inf_dates.fin_wk
                
WHERE       notes = 'Weekly COMPLETED'
            AND ([2MB/sub]) = 'ETH' 
            AND dbo.inf_dates.date > CONVERT(datetime, '2017-04-03 00:00:00', 102)
            
GROUP BY   t1.region 
           ,dbo.inf_dates.months 

As you can see I am trying to group rows with months instead of the weeks that I have in my table by creating a month column and grouping the weeks together. When I do a case ** ** like CASE WHEN t1.Week < '5' THEN 'APR' I get the right results but it forces me to group by weeks which is not what I want. The two months column in the table are different by the way.

sql sql-server case