I am using DB2 9.5 UDB on windows
I want to update multiple rows in a single sql statement.
I have a table which has an id,date start, date end, sequence.
The last row has a date end of 9999-12-31 and date start 01-01-2008
the row before has a null date end and date start 01-01-2007
the date end of this row needs setting to the previous rows date start minus 1 day (31-12-2007)
I have created this query which gets me the rows with the correct dates
and sequence
SELECT A.id, A.SEQUENCE, A.DATE_start, DATE(B.DATE_start) - 1 DAY AS DATE_end1, B.SEQUENCE, B.DATE_start
FROM HOLD A, HOLD B
WHERE A.id = B.id
AND A.DATE_end IS NULL
AND A.SEQUENCE = ( B.SEQUENCE -1)
This returns
ID SEQUENCE DATE_start DATE_end1 SEQUENCE DATE_start
--------------- ----------- -------------- ------------ ----- ------------
200000 5 2004-07-12 31/07/2004 6 2004-08-01
200000 6 2004-08-01 29/07/2007 7 2007-07-30
200000 7 2007-07-30 14/10/2007 8 2007-10-15
i need to update row 5,6,7 with the date end1 value.
I have tried various methods - i am trying to do this with sql only
UPDATE HOLD
SET DATE_end =
( SELECT DATE(B.DATE_start) - 1 DAY
FROM HOLD A, HOLD B
WHERE A.id = B.id
AND A.DATE_end IS NULL
AND A.SEQUENCE = ( B.SEQUENCE -1))
this returns a -811.
I have tried other where statements but this does not work.
Advice whould be greatly appreciated.