Friday, February 10, 2012

Changing year in field

Hi all:
I need to change the year to many records that, by mistake, were put with a 2007 date, but they should be still with 2006, can anyone help me ?
I use Sql Server 2000 and the field is of type datetime
Thanks:eek:first make a backup.

then write a select statement for the rows that need to be updated, and make sure it's correct (that is, it contains all the rows that need fixing, and no others):

select * from mytable where <some criteria>

then you can apply an update.

update mytable
set mycol=dateadd(year, -1, mycol)
where <some criteria>

No comments:

Post a Comment