I am in need to create a report with dynamic columns.
The columns are weeks number, starting from actual week (12-2022), going back for 52 weeks (13-2021) in a rolling year way.
The report will be executed once per week, so next week I'll have 13-2022 up to 14-2021 and so on.
Data comes from some columns:
External consultant in charge of a customer, name of the customer, name of the person of the customer who provided an order, weeks number, year number, email address, day of the order (for this field duplicates are admitted).
I am in need to have the number of the orders done each week, using a normal sql count.
I can eventually create a pivot with rolling week numbers, with some code like that:
select * into tab from cust_table
declare @sql nvarchar(max), @cols varchar(max)
select @cols = coalesce(@cols + ',', '') + ''
In this case I should create a variable and use those variables (52, like the number of the weeks in a year) and define them.
Is it there any more simple solution?
Thank you!