My financial year start from 01-Jul to 30-Jun every year.
I want to find out all financial year wise periods for a given date range.
Let’s say, The date range is From_Date:16-Jun-2021 To_Date 31-Aug-2022. Then my output should be like
Start_Date, End_date
16-Jun-2021, 30-Jun-2021
01-Jul-2021, 30-Jun-2022
01-jul-2022, 31-Aug-2022
Please help me query. First record Start_Date must start from From_Date and Last record End_Date must end at To_Date
2
Answers
You want to create multiple records from one record (your date range). To accomplish this, you will need some kind of helper table.
In this example I created that helper table using
GENERATE_SERIES
and use it to join it to your date range, with some logic to get the dates you want.dbfiddle
This should work for the current century.
Looks well as a parameterized query too with
'16-Jun-2021'
and'31-Aug-2022'
replaced by parameter placeholders.