I have a table with a period column which needs to be split into multiple rows per month
The table has lots of records like this:
ID, PERIOD, AMOUNT
1, 201812-201902, 300.00
2, 201804-201903, 1150.00
3, 201901-201902, 200.00
I need to following query result:
1, 12-2018, 100.00
1, 01-2019, 100.00
1, 02-2019, 100.00
2, 04-2018, 95.83
2, 05-2018, 95.83
2, 06-2018, 95.83
2, 07-2018, 95.83
2, 08-2018, 95.83
2, 09-2018, 95.83
2, 10-2018, 95.83
2, 11-2018, 95.83
2, 12-2018, 95.83
2, 01-2019, 95.83
2, 02-2019, 95.83
2, 03-2019, 95.83
3, 01-2019, 100.00
3, 02-2019, 100.00
How to achieve this in MS-Access SQL?
You can create this with a series of queries (that I had on hand):
Save this as Ten:
Save this as MonthDateRange:
Then build your final query using your table Periods:
Now, call this passing a start and end date beyond your range of periods, say 2000-01-01 and 2020-01-01, and the output will be:
To have the amount split over the periods, include a subquery:
to obtain this output: