In need to split lines with From date and To date in multiple months.
I want to split like this.Target
Sample 1
- 10/02/2023 - 28/02/2023
Target
- 10/02/2023 - 28/02/2023
Sample 2
- 10/02/2023 - 29/08/2023
Target
- 10/02/2023 - 28/02/2023
- 01/03/2023 - 31/03/2023
- 01/04/2023 - 29/08/2023
Sample 3
- 01/04/2022 - 31/03/2023
Target
- 01/04/2022 - 28/02/2023
- 01/03/2023 - 31/03/2023
I succeed in first steps but I'm now stucked For the moment I can only do like this[Existing] But in yellow wrong values,
Here below my code
CASE WHEN qd.valid_from >= TRUNC(add_months(qd.valid_from,COLUMN_VALUE - 1),'MM')
THEN
TRUNC(qd.valid_from)
ELSE
TRUNC(add_months(qd.valid_from,COLUMN_VALUE - 1),'MM')
END new_start_date,
CASE WHEN last_day(TRUNC(add_months(qd.valid_from,COLUMN_VALUE - 1),'MM')) >= last_day(TRUNC(add_months(qd.valid_from,2),'MM'))
THEN
TRUNC(qd.valid_to)
ELSE
TRUNC(last_day(TRUNC(add_months(qd.valid_from,COLUMN_VALUE - 1),'MM')))
END new_end_date
FROM QUOTATIONS_UO QH
),
TABLE(
CAST(
MULTISET
(
SELECT LEVEL
FROM dual
CONNECT BY add_months(TRUNC(qd.valid_from,'MM'),LEVEL - 1) <= add_months(TRUNC(qd.valid_from,'MM'),2)
) AS sys.OdciNumberList
)
)
)
It is unclear what is it about months february and march vs all the others, but if you want to split dates by months then maybe this could help you:
... which with sample data like here:
... results as: