I have a table which has different interval invoice. Please see sample data below:
Invoice_Start_Date Invoice_End_Date Amount
1/1/2019 2/1/2019 12
1/1/2019 1/1/2020 84
1/1/2019 1/1/2021 140
I need to split this data into monthly invoice. In this case First record will be as is. Second record should be split into 12 records with amount of 84/12 for each record. Third record should be split into 24 records with amount of 140/24 for each record.
Expected Output:
Invoice_Start_Date Invoice_End_Date Amount
1/1/2019 2/1/2019 12
1/1/2019 2/1/2019 7
2/1/2019 3/1/2019 7
3/1/2019 4/1/2019 7
4/1/2019 5/1/2019 7
.........etc
Can someone please advise. I was thinking of writing many union statements ( one for each month but I realized my interval can be 12 months or 24 months etc. so it won't work)