I need a create a prompt such that, if a report runs every 2nd of the month. it supposed to pick previous month (start date & end date) as prompt for data retrieval.
How to achieve this requirement? Database is Oracle.
you can use a case statment to decide if it’s the 2nd.
and you can use ADD_MONTHS(YOUR_COLUMN,-1) to recieve the date 1 month before the date in “YOUR_COLUMN”
For example:
SELECT ...
FROM ...
WHERE
TABLE.DATES >= CASE WHEN TO_CHAR(SYSDATE,'DD')='02' THEN ADD_MONTHS(@PROMPT('FROM'...),-1) ELSE @PROMPT('FROM'...) END
AND TABLE.DATES <= CASE WHEN TO_CHAR(SYSDATE,'DD')='02' THEN ADD_MONTHS(@PROMPT('TO'...),-1) ELSE @PROMPT('TO'...) END