October 6, 2003 at 10:01 pm
Hi everyone,
I need to update just part of a series of dates in a table. That is the full date is 2000-12-02 16:41:00.000 and I need it to be 2003-10-06 16:41:00.000. There are thousands of these where ofcourse the times are different. I just need to update the 2000-12-02 part to 2003-10-06. I tried updating using replace but it throws no error but does not update the fields. Here is an example of my update statement:
update table_name
set col_name =REPLACE(CAST(col_name AS VARCHAR(40)),'2000-12-02','2003-10-06')
where blah blah
October 6, 2003 at 10:22 pm
Hi vikramnat,
Try using the following query
update table_name set col_name =DATEADD(d,DATEDIFF(d,col_name,'9-1-2003'),col_name) where .......
October 6, 2003 at 10:37 pm
Hi vkpalivela,
Thanks - that did the trick - help is greatly appreciated. Can you please explain the query real quick.
October 6, 2003 at 11:16 pm
DATEDIFF gives the date difference between two dates i.e number of days and I am adding these days to the current date by using DATEADD function. For further info please refer to BOL.
quote:
Hi vkpalivela,Thanks - that did the trick - help is greatly appreciated. Can you please explain the query real quick.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply