Update a running sql script to update the last 2 years based on today's date

72 views Asked by At

I currently have a simple sql script (in Oracle) that updates based a date range >='01JUN13'. I'm trying to modify this script to automatically update based on the last two years based on today's date. So the next month, I need the last two years of data greater than or equal to July 2013. Thanks.

1

There are 1 answers

0
APC On

It's not entirely clear from your question whether you want the date range to start from exactly two years ago, to the day , or from the start of the month.

Matching to the day:

select * from your_table
where date_col >= add_months(trunc(sysdate), -24)
/

Matching to the first day of the month:

select * from your_table
where date_col >= add_months(trunc(sysdate, 'MON'), -24)
/