Question

I would like to run a query on a number of incorrectly time-stamped rows (SQL 2005) and replace the DAY value only. My initial thought was just to use the REPLACE function as follows:

-- date correction
UPDATE mytable
SET [date] = REPLACE([date], '2014-02-20', '2014-02-27')
WHERE [date] LIKE '2014-02-20%'

..but that proved to be unsuccessful most likely because of the given column data-type. Any suggestions ?

Was it helpful?

Solution

You could also just make a DATEADD :

UPDATE mytable
SET [date] = DATEADD(DAY, 7, [date])
WHERE [date] >= '2014-02-20' AND [date] < '2014-02-21'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top