I would like to return the RATE that is 5 months prior to the EFFECTIVE_DATE. If that date is on a Saturday then I would like to move the EFF_DATE back 1 day so that the EFFECTIVE_DATE is on a Friday. This is the code I am using but it so far returns no values:
DEFINE EFF_DATE = TO_DATE('05/31/2012','MM/DD/RRRR')
SELECT RATE, EFFECTIVE_DATE
FROM RATES_ALL
WHERE EFFECTIVE_DATE IN
CASE
WHEN TO_CHAR(add_months(&&EFF_DATE, -5), 'DAY') = 'SATURDAY'
THEN
(
SELECT EFFECTIVE_DATE
FROM RATES_ALL
WHERE EFFECTIVE_DATE = add_months(&&EFF_DATE, -5)-1
)
END;
I don’t know Oracle, but assuming that the reason you check for Saturdays is because there’s no entry in the RATES_ALL table for Saturdays, then why not simply something like: