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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

fralo
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.

jimf
Flowing Fount of Yak Knowledge

USA
2875 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'

Jim

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

fralo
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  
 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.04 seconds. Powered By: Snitz Forums 2000