I am passing two parameters - Month and year
Month can be 01/2022, 02/2022, 03/2022 etc Year can be 2022, 2021,2020
Year is mandatory
I have a condition in the query that compares these dates -
SELECT Max(acrl2.accrual_period)
FROM anc_per_accrual_entries acrl2
WHERE person_id = 123
AND acrl2.plan_id = 1678
acrl2.accrual_period
and to_char(acrl2.accrual_period,'yyyy') = NVL(:p_year,to_char(acrl2.accrual_period,'yyyy'))
AND acrl2.accrual_period <= Nvl((
CASE
WHEN :p_month IS NOT NULL
THEN To_date(To_char(Last_day(To_date(:p_month, 'yyyy/mm')), 'yyyymmdd'), 'yyyymmdd')
WHEN :p_year IS NOT NULL
THEN To_date(:p_year || '1231', 'yyyymmdd')
END) ,sysdate)
When i pass one month - say 01/2022 - I am getting the correct output. or when i am passing just 2021, I am getting an output. The issue is when i select multiple months 01/2022, 02/2022 or 2021,2022.
I know i can use in clause. But I am not being able to use it with <=