Input
ID StartDate EndDate
ABC 12/14/2020 1/14/2021
XYZ 12/13/2020 12/23/2021
DEF 12/3/2020 2/3/2021
Output
ID StartDate EndDate YEAR MONTH No. Of Days
ABC 12/14/2020 12/31/2020 2020 12 18
ABC 1/1/2021 1/14/2021 2021 1 14
XYZ 12/13/2020 12/23/2020 2020 12 11
DEF 12/3/2020 12/31/2020 2020 12 29
DEF 1/1/2021 1/31/2021 2021 1 31
DEF 2/1/2021 2/3/2021 2021 2 3
Input and output samples are given above. Each record has to split by each month across the given date range.
Idea here is to generate data-set with all dates filled in between start-date and end-date. Used
table(split_to_table(repeat(',',TIMESTAMPDIFF(day, sdate,edate)-1),',')), for same. Once we have all dates, just select the relevant dates.