sql server - Dynamic SELECT does not work using @param in GROUP BY -
i'm trying following:
select case when @aggregation_zeit = 'day' day when @aggregation_zeit = 'month' month when @aggregation_zeit = 'year' year end time_field, ... group year, case when @aggregation_zeit = 'day' month when @aggregation_zeit = 'month' month end, case when @aggregation_zeit = 'day' day end
but keeps saying month , day invalid in select-list because not contained in aggregate function.
how can realize this?
thanks, felix
i'm assuming day, month, year numeric columns in table, if not let me know , i'll change answer.
select case when @aggregation_zeit = 'day' cast(datefromparts([year], [month], [day]) varchar(12)) when @aggregation_zeit = 'month' str([year]) + '/' + str([month]) when @aggregation_zeit = 'year' str([year]) end time_field, ... group case when @aggregation_zeit = 'day' cast(datefromparts([year], [month], [day]) varchar(12)) when @aggregation_zeit = 'month' str([year]) + '/' + str([month]) when @aggregation_zeit = 'year' str([year]) end
Comments
Post a Comment