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])

You can pull the current column names from sys.columns. You can use the XML "trick" to concatenate the names or you can do a quick cursor loop to do it. For the number of columns in a table, a cursor won't be that terrible and is easier code to understand/change.

Hi Can you give an example to how to do loop with cursor?