In my database I have a View Revenues with fields ProductID,EditionID, Year, January, February, March,..., December.
I need to display in Excel for each ProductID and EditionID all the year and months revenues in a single record. In order to do that I execute the query:
select *
from Revenus r1
join Revenues r2
on r1.ProductID = r2.ProductID
and r1.EditionID = r2.EditionID
where r1.[Year] <> r2.[Year]
That works perfectly if there at the most two different years per ProductID andEditionID. However since the sheet will be used also for forecasting purposes, I have been asked to have the years and month with a 10 years horizon. That means besides the data already existing in the database, given starting year 2013, I must have years and related month till 2023. The months related data must be equal to zero if there is no year year yet in the database.
I tried with pivot table but it does not sound as the right solution. I might try with a fore each but I read on the web that is a bad practice. The best solution, yet a bit dirty, might be to join the existing data with a View built on the fly with empty records for months and increase the year for each "iteration". Anybody might help? Thanks
EXAMPLE
Same as 2015 till 2023