SQL Server Sum table fields based on params -
i have table containing values 12 different months
table { january int, february int, etc. }
and need sum values specific months numbers keep in table (the number of months sum can vary 1 12):
declare @months table ( number int )
so i'll surely need big case , cte don't know how achieve this.
the case statement isn't bad:
select sum((case when m.month = 1 jan else 0 end) + (case when m.month = 2 feb else 0 end) + . . . (case when m.month = 12 dec else 0 end) ) atable cross join @months m;
you might want group by
well. above return 1 row entire table.
Comments
Post a Comment