SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

161 Posts

Posted - 01/22/2013 :  11:02:55  Show Profile  Reply with Quote
I have a date field with many dates showing the year 1901 which I need to update to 2001. Is there a way to do this?

I know there is a DATEPART function which allows searching only for the year portion of a field (i.e. DATEPART(yy, date_field)).

Can I run an update which will update all rows with a date of 1901-??-?? to 2001-??-??

Thanks for any help you could provide.

Flowing Fount of Yak Knowledge

2870 Posts

Posted - 01/22/2013 :  11:18:28  Show Profile  Reply with Quote
Maybe just this
UPDATE yourTable
SET yourDate = DATEADD(year,100,yourDate)
WHERE yourDate between '19010101' and '19011231'


Everyday I learn something that somebody else already knew
Go to Top of Page

Posting Yak Master

161 Posts

Posted - 01/22/2013 :  11:29:35  Show Profile  Reply with Quote
Hey you an alright fella!

That worked. Thanks a lot.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000