I currently have entries
InvoiceList Table
InvoiceID StoreCustomerID IssuedDate Amount IsPenalty EmployeeID ----------- --------------- ---------- ----------- ----------- ----------- 1 13 2007-01-12 244 0 41 2 31 2007-04-05 81 0 34 3 23 2007-01-09 184 0 46 4 28 2007-11-21 231 0 17 5 36 2006-09-19 121 0 22 6 28 2006-10-24 240 0 17 7 15 2006-12-11 193 0 47 8 21 2007-01-15 172 0 4
InvoiceID automatically increases. I want to update IssuedDate by increasing the date of the previous row. I want to update it as follows
InvoiceID StoreCustomerID IssuedDate Amount IsPenalty EmployeeID ----------- --------------- ---------- ----------- ----------- ----------- 1 13 2007-01-12 244 0 41 2 31 2007-01-13 81 0 34 3 23 2007-01-14 184 0 46 4 28 2007-01-15 231 0 17 5 36 2007-01-16 121 0 22 6 28 2007-01-17 240 0 17 7 15 2007-01-18 193 0 47 8 21 2007-01-19 172 0 4
I currently have this select statement and it works well. But how can I use this to update IssuedDate ?
WITH SequenceDate AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY IssuedDate) RowNumber FROM Invoice ) SELECT RowNumber, DATEADD(d, RowNumber - 1, b.IssuedDate) FROM SequenceDate ORDER BY RowNumber
UPDATE 1
I am terribly sorry for the first message, because the instruction given to me was not correct. Dates should not increase because we are not allowed to change the entries in the table, except that we can only change the dates in ascending order. It should be.
InvoiceID StoreCustomerID IssuedDate Amount IsPenalty EmployeeID ----------- --------------- ---------- ----------- ----------- ----------- 1 13 2006-09-19 244 0 41 2 31 2006-10-24 81 0 34 3 23 2006-12-11 184 0 46 4 28 2007-01-09 231 0 17 5 36 2007-01-12 121 0 22 6 28 2007-01-15 240 0 17 7 15 2007-04-05 193 0 47 8 21 2007-11-21 172 0 4
source share