In my web application I have a query with a control parameter that enables switching between two different reports: one that groups by 'Section' and the other that groups by 'Section' and 'Date'
I'm doing this trick:
declare @switch nvarchar(1) set @switch = CASE WHEN @checkbox = 1 THEN '' ELSE NULL END SELECT SUM(minutes) as Time, Section, COALESCE(@switch,Date) as Date FROM Table GROUP by Section, COALESCE(@switch,Date)
That works, but has the ugly side effect that the empty date is then displayed as '1900-01-01' (which I will hide on the webside). I'm puzzeling over a function that returns a column or Null based on the value (1/0) of the control parameter.
Someone has a better solution?