0

I am super new to Sql server and trying to create a pivot table. I have the following code when I know the columns but how would I change it when I don't know the column names?

Background: I will be creating a report every month to track the revenue for the last 12 months. The best way to do this will be to use YYYY-MM to organize the data chronologically.

select * from (SELECT storename,brandname,month_year,revenue
FROM sample_data)
    as src  
PIVOT  (
sum(revenue) 
FOR  monthname IN([2021-01], [2021-02], [2021-03]
)  
) AS pivotable;

What would be the best way to resolve this issue?

Any help would be greatly appreciated. Thank you

0 Answers0