none
I have column name with dates which comes from a table and changes from current month to last 41 month. and i have to write the column name again and again to reach the desired output. Is there any way I can take the column name dynamically. RRS feed

  • Question

  • sales_Net.[ID], sales_Net.Category, sales_Net.Geography, sales_Net.Period, sales_Net.[Actual_Volume], sales_Net.[Actual_Value]  , 'Historic' as [Type] Into Sales_Final

    From

     ( Select ID, Category, Geography,[Net Sales Volume 2015-11], [Net Sales Volume 2015-12], [Net Sales Volume 2016-01], [Net Sales Volume 2016-02], [Net Sales Volume 2016-03],[Net Sales Volume 2016-04], [Net Sales Volume 2016-05], [Net Sales Volume 2016-06], [Net Sales Volume 2016-07], [Net Sales Volume 2016-08], [Net Sales Volume 2016-09], [Net Sales Volume 2016-10], [Net Sales Volume 2016-11], [Net Sales Volume 2016-12],[Net Sales Volume 2017-01], [Net Sales Volume 2017-02], [Net Sales Volume 2017-03], [Net Sales Volume 2017-04], [Net Sales Volume 2017-05], [Net Sales Volume 2017-06],[Net Sales Volume 2017-07], [Net Sales Volume 2017-08],  [Net Sales Volume 2017-12], [Net Sales Volume 2018-01], [Net Sales Volume 2018-02], [Net Sales Volume 2018-03], [Net Sales Volume 2018-04],[Net Sales Volume 2018-05], [Net Sales Volume 2018-06], [Net Sales Volume 2018-07],[Net Sales Volume 2018-08], [Net Sales Volume 2018-09],[Net Sales Volume 2018-10],[Net Sales Value 2015-11],[Net Sales Value 2015-12], [Net Sales Value 2016-01], [Net Sales Value 2016-02], [Net Sales Value 2016-03],[Net Sales Value 2016-04], [Net Sales Value 2016-05], [Net Sales Value 2016-06], [Net Sales Value 2016-07] [Net Sales Value 2017-03],[Net Sales Value 2017-04], [Net Sales Value 2017-05], [Net Sales Value 2017-06],[Net Sales Value 2017-07],[Net Sales Value 2017-08], [Net Sales Value 2017-09], [Net Sales Value 2017-10], [Net Sales Value 2017-11], [Net Sales Value 2017-12], [Net Sales Value 2018-01], [Net Sales Value 2018-02], [Net Sales Value 2018-03], [Net Sales Value 2018-04],[Net Sales Value 2018-05], [Net Sales Value 2018-06], [Net Sales Value 2018-07], [Net Sales Value 2018-08], [Net Sales Value 2018-09],[Net Sales Value 2018-10]

      From Sales_Raw ) sales

         cross apply (

     values ( Sales.ID, sales.Category, Sales.geography,'11/1/2015',sales.[Net Sales Volume 2015-11], sales.[Net Sales Value 201511]  ), ( Sales.ID, sales.Category, Sales.geography,'12/1/2015', sales.[Net Sales Volume 2015-12], sales.[Net Sales Value 201512] ), ( Sales.ID, sales.Category, Sales.geography,'1/1/2016', sales.[Net Sales Volume 2016-01], sales.[Net Sales Value 201601]),( Sales.ID, sales.Category,Sales.geography,'2/1/2016', sales.[Net Sales Volume 201602], sales.[Net Sales Value 201602]   ),( Sales.ID,sales.Category, Sales.geography,'3/1/2016', sales.[Net Sales Volume 2016-03], sales.[Net Sales Value 201603]   ),( Sales.ID,sales.Category, Sales.geography,'8/1/2016', sales.[Net Sales Volume 2016-08], sales.[Net Sales Value 201608]   ),  ( Sales.ID, sales.Category, Sales.geography,'9/1/2017',sales.[Net Sales Volume 2017-09], sales.[Net Sales Value 201709]   ), ( Sales.ID, sales.Category,Sales.geography,'10/1/2017', sales.[Net Sales Volume 2017-10], sales.[Net Sales Value 201710]   ), (Sales.ID, sales.Category, Sales.geography,'11/1/2017', sales.[Net Sales Volume 2017-11], sales.[Net Sales Value 201711]   ), ( Sales.ID, sales.Category, Sales.geography,'12/1/2017', sales.[Net Sales Volume 2017-12], sales.[Net Sales Value 201712]   ),( Sales.ID, sales.Category, Sales.geography,'1/1/2018', sales.[Net Sales Volume 2018-01], sales.[Net Sales Value 201801]   ),( Sales.ID, sales.Category,Sales.geography,'2/1/2018', sales.[Net Sales Volume 2018-02], sales.[Net Sales Value 201802]   ), (Sales.ID, sales.Category, Sales.geography,'3/1/2018', sales.[Net Sales Volume 2018-03], sales.[Net Sales Value 201803]   ),( Sales.ID, sales.Category, Sales.geography,'4/1/2018', sales.[Net Sales Volume 2018-04],sales.[Net Sales Value 201804]   ), ( Sales.ID, sales.Category, Sales.geography,'5/1/2018', sales.[Net Sales Volume 2018-05], sales.[Net Sales Value 201805]   ), ( Sales.ID, sales.Category, Sales.geography,'6/1/2018',sales.[Net Sales Volume 2018-06], sales.[Net Sales Value 201806]   ),  ( Sales.ID, sales.Category,Sales.geography,'7/1/2018', sales.[Net Sales Volume 2018-07], sales.[Net Sales Value 201807]   ),( Sales.ID,sales.Category, Sales.geography,'8/1/2018', sales.[Net Sales Volume 2018-08], sales.[Net Sales Value 201808]   ),( Sales.ID, sales.Category, Sales.geography,'9/1/2018', sales.[Net Sales Volume 2018-09], sales.[Net Sales Value 201809]   ),( Sales.ID, sales.Category, Sales.geography,'10/1/2018', sales.[Net Sales Volume 2018-10], sales.[Net Sales Value 2018-10]   )

     ) sales_Net(ID, Category, Geography, Period, [Actual_Volume], [Actual_Value])


    Sarita kumari

    Tuesday, March 19, 2019 10:18 AM

Answers