I have below query which i am using for reporting in Cognos. I am doing reporting every week on Monday for the previous week from Monday till Sunday.
Currently this date is hardcoded but i want to make it dynamic so that everytime when i run this report on Monday i dont have to change the date for previous week.
Is it possible i can make DAY_DATE dynamic using something like sysdate in select query ?
select ID,NAME,DAY_DATE
from TEST_REPORT
WHERE DAY_DATE BETWEEN to_date ('20170904', 'YYYYMMDD') and to_date ('20170910', 'YYYYMMDD');
You can calculate start and end dates of previous week from the current date using TRUNC (date) function.
Let say you are running the query on monday
2017-09-11, then on friday2017-09-15, and the query must always generate a report for previous week.This query calculates a start date of the current week:
To calculate a start date of the previous week, substract 1 day from the above dates, and use TRUCT again:
So, in your query just use this clause (date >= than a start of previous week and < that a start of current week):