Matt Johnson
Matt Johnson

Reputation: 11

Adding 7 days to all rows with a date from the past 7 days

I am charged with the task of solving a scenario based on the following: The database server had been reset with the wrong date and time without anyone knowing. UPDATE any order date in the past week to add 7 days.

The Orderdate is stored in ORDERS.ORDERDATE. I tried using the following code and it fails:

UPDATE ORDERS 
SET  ORDERDATE,DATEADD(day,7,OrderDate)
WHERE DATEDIFF >= (
    DAY, 
    DATEDIFF(DAY, @ORDERDATE, -7), 
    GETDATE());

Can someone provide me with the proper code?

Any assistance is appreciated!

Upvotes: 1

Views: 1288

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522084

Your syntax appears to be for SQL Server, but you tagged the question for Oracle. In any case, a correct UPDATE query in Oracle should look something like this:

UPDATE ORDERS
    SET ORDERDATE = ORDERDATE + INTERVAL '7' DAY
    WHERE ORDERDATE > SYSDATE - INTERVAL '7' DAY

Here SYSDATE is a DATE object representing the current date and time.

Upvotes: 2

Ricardo Arnold
Ricardo Arnold

Reputation: 913

You can maybe try with

Update ORDERS
   SET ORDERDATE = ORDERDATE + 7
WHERE SYSDATE - ORDERDATE <= 7;

Upvotes: 1

Related Questions