I have the following query-
(SELECT DISTINCT accrual_period
FROM anc_per_accrual_entries a,
anc_per_plan_enrollment b
WHERE a.per_plan_enrt_id = b.per_plan_enrt_id
--AND a.accrual_period = b.last_accrual_run
AND b.work_term_asg_id = paam.work_terms_assignment_id
AND accrual_period = (SELECT Max(acrl2.accrual_period)
FROM anc_per_accrual_entries acrl2
WHERE person_id = paam.person_id
AND acrl2.plan_id = appe.plan_id
AND acrl2.accrual_period <= sysdate)
AND b.plan_id = appe.plan_id
AND b.person_id = paam.person_id
AND sysdate BETWEEN b.enrt_st_dt AND b.enrt_end_dt)
I have the following query to fetch accrual_period as of the sysdate or today. Now there are three parameters -
P_YEAR - 2022
P_QUARTER - 2022 Q 4
P_MONTH - 2022 / 12
If the year is passed - I want the query to fetch the data as of current month and date of that year. i.e. the sysdate in the query should be replaced by 2021/05/06 if i pass year as 2021.
If i pass Year and quarter of that year then the sysdate in the query should be replaced by that quarter. i.e. if the quarter is 2021 Q 1, then it should be calculated as of the last date of that quarter i.e. 31 march 2021.
If I pass month, then the last day of month
How can i achieve it in the same query ?