1

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.

Select product_Aggr.[ID], product_Aggr.group_code, product_Aggr.[Product_desciption], product_Aggr.Period, 
           product_Aggr.[Actual_Volume], product_Aggr.[Actual_Value]  
    Into Sales
    From 
         ( select * from ##temp  ) product
           cross apply (
                         values ( product.ID, product.group_code, product.[Product_desciption],'10/1/2015',product.[Total Quantity 2015-10], product.[Total Amount 2015-10]  ),
                                ..
                                ..
                                ..
                                ( product.ID, product.group_code, product.[Product_desciption],'10/1/2019', product.[Total Quantity 2019-01], product.[Total Amount 2019-01]   )

                        ) product_Aggr(ID, group_code, [Product_desciption], Period, [Actual_Quantity], [Actual_Amount])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.