This is my data:
I need a Fiscal Year to Date logic that will gather all previous months starting October.
However, for October 2018 I want to start form 15th, for remaining years it must start from October 1st.
Expected result would be all dates from October till last day of previous month.
For testing purpose I replaced

sysdate, 'MM'
with to_date('31-DEC-18'), 'MM'
Below is working but wondering if I can improve it...
PER_PERIOD_START_DATE between
(CASE
WHEN (a.PER_MONTH_NUM = 10 and extract( year from a.PER_PERIOD_START_DATE) = 2018)
THEN Add_Months(Trunc(Add_Months(to_date('31-DEC-19'),6),'YYYY'),-3) +14
ELSE Add_Months(Trunc(Add_Months(to_date('31-DEC-19'),6),'YYYY'),-3)
END
)
and trunc(to_date('31-DEC-19'), 'MM')-1
Final code:
where PER_PERIOD_START_DATE between
(CASE
WHEN (PER_MONTH_NUM = 10 and extract( year from PER_PERIOD_START_DATE) = 2018)
THEN Add_Months(Trunc(Add_Months(sysdate,6),'YYYY'),-3) + 14
ELSE Add_Months(Trunc(Add_Months(sysdate,6),'YYYY'),-3)
END
)
and trunc(sysdate, 'MM')-1
Asked by marcin2x4
(145 rep)
Nov 14, 2018, 03:16 PM
Last activity: May 19, 2025, 04:05 PM
Last activity: May 19, 2025, 04:05 PM