Error Grouping By Multiple Columns using CASE Is it possible to group by multiple columns in a CASE statement? I get error "Incorrect syntax near ','." in below code...

SELECT
  CASE 
     WHEN Type = 'Test'
       THEN Description
     ELSE MAX([Description])                
  END AS 'Description'
GROUP BY
CASE
    WHEN Type = 'Test'
        THEN Description
    ELSE ''
END,
Type, Account, Structure
I guess that when Type has a certain value ('Test'), you want the Structure and Description columns to be considered for the grouping but otherwise to not use them at all. This is one way to do this:

GROUP BY
    Type, Account,
    CASE WHEN Type = 'Test' THEN Structure ELSE '' END, 
    CASE WHEN Type = 'Test' THEN Description ELSE '' END


The '' should be a (any) constant expression that has the same datatype with Structure and Description respectively.

Alternatively, you could separate the 2 cases, which will give you more flexibility on adjusting the SELECT lists:

SELECT 
    ---
FROM
    ---
WHERE
    Type = 'Test'
GROUP BY
    Type, Account, Structure, Description

UNION ALL

SELECT 
    ---
FROM
    ---
WHERE
    (Type &lt;&gt; 'Test' OR Type IS NULL)
GROUP BY
    Type, Account ;