sql - how to implement transport for sqlresult set? -
january february march april 500 200 300 400
below code this:
select sum (case when [month] = 1 forecastdemand else 0.0 end ) january, sum(case when [month] = 2 forecastdemand else 0.0 end) february, sum(case when [month] = 3 forecastdemand else 0.0 end) march , sum(case when [month] = 4 forecastdemand else 0.0 end) april , sum(case when [month] = 5 forecastdemand else 0.0 end) may , sum(case when [month] = 6 forecastdemand else 0.0 end) june , sum(case when [month] = 7 forecastdemand else 0.0 end) july , sum(case when [month] = 8 forecastdemand else 0.0 end) august , sum(case when [month] = 9 forecastdemand else 0.0 end) september , sum(case when [month] = 10 forecastdemand else 0.0 end) october , sum(case when [month] = 11 forecastdemand else 0.0 end) november , sum(case when [month] = 12 forecastdemand else 0.0 end) december forecastreorder result productid = 2
how can make
month result january 500 february 200 march 300 april 400
i know can use pivot unpivot how can apply it?? thank in advanced :)
is want?
select (case when [month] = 1 'january' when [month] = 2 'february' when [month] = 3 'march' when [month] = 4 'april' end) mon, sum(forecastdemand) result forecastreorder fr productid = 2 , [month] in (1, 2, 3, 4) group [month] order [month];
Comments
Post a Comment