Farhad-Taran
Farhad-Taran

Reputation: 6512

how to add multiple columns to a group by case?

I have the following group by clause on my query which uses a case statement but I want to add another column to the group by too:

        group by case @dateType

WHEN 'Daily' then i.overridedate
WHEN 'Weekly' then dateadd(day,-1*datepart(weekday,i.overridedate)+1,i.overridedate) 
WHEN 'Monthly' THEN DATEADD(day, -1*DATEpart(day,i.overridedate)+1, i.overridedate) 
WHEN 'Quarterly' THEN dateadd(mm,-3,DATEADD(qq, DATEDIFF(qq,0,i.overridedate )+1, 0)) END

how do I add another column to this group by?

Upvotes: 1

Views: 71

Answers (1)

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11599

group by case @dateType
WHEN 'Daily' then i.overridedate
WHEN 'Weekly' then dateadd(day,-1*datepart(weekday,i.overridedate)+1,i.overridedate) 
WHEN 'Monthly' THEN DATEADD(day, -1*DATEpart(day,i.overridedate)+1, i.overridedate) 
WHEN 'Quarterly' THEN dateadd(mm,-3,DATEADD(qq, DATEDIFF(qq,0,i.overridedate )+1, 0)) END
--Edited
,
col1,
col2,
etc..,
coln

Upvotes: 3

Related Questions