Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating and replacing dates

Author  Topic 

mungojerry312002
Starting Member

4 Posts

Posted - 2007-12-17 : 11:51:25
I'm the assistant to the assistants assistant and have no SQL base at all but have to change dates in our SQL database. I've got the script for how to do an update/replace for non date fields and have been successful at that. Unfortunately when I try to use the script to change date fields it does not work. It goes through the process and acts like it is working (even asks me if I want to update the records) but when I look in the database the dates have not changed. Below is the script that I am using, any help you can give me will help me keep my job (and pay for the beer I'm sure to need after work today) Thanks in advance for your help. I am trying to change the date '30/08/2007' to '28/08/2008'.

My Script:

update Main_table set valuedate=replace(valuedate,'30/08/2007','28/08/2008')
where country='FR'
and valuedate='30/08/2007'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-17 : 11:55:08
update Main_table set valuedate='28/08/2008'
where country='FR'
and DATEADD(d,DATEDIFF(d,0,valuedate),0)='30/08/2007'
Go to Top of Page

mungojerry312002
Starting Member

4 Posts

Posted - 2007-12-17 : 11:59:54
visakh16 thanks a ton, worked like a charm
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-17 : 12:04:49
Cheers mungojerry312002
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 14:49:42
For speed, use

update Main_table
set valuedate = '28/08/2008'
where country = 'FR'
and valuedate >= '30/08/2007'
and valuedate < '31/08/2007'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -