tsql update statement to amend year in datetime field

I have a table with startdate and enddate of type date time

How can I do a t-sql update statement to amend the year part in the datetime field
Currently all datetime fields are in 2008
2008-07-20 00:00:00.000

However I want the year to change to 2010 so it would look like

2010-07-20 00:00:00.000


mugseyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mdagisCommented:
Update table xtable
set datecolumn = dateadd(Year, 2, datecolumn )
0
mugseyAuthor Commented:
Ok thanks can u amend so it just updates row that only have a year of 2008?  So to ignore say 2007
0
flytox06Commented:
UPDATE yourtable
SET col = DATEADD(year, 2, col)
WHERE YEAR(col) = 2008;
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ralmadaCommented:
Update table xtable
set datecolumn = dateadd(Year, 2, datecolumn ) where year(datecolumn)=2008
 
0
ralmadaCommented:
Actually, using the function year is not the best approach if you have lots of records in your table since it will not take advantage of the indexes. The best way to take advantage of the indexes is doing something like this
Update table xtable
set datecolumn = dateadd(Year, 2, datecolumn ) where datecolumn >= '2008-01-01' and datecolumn < '2009-01-01'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
halfbloodprinceCommented:
Try this:
Update Orders
Set OrderDate = DateAdd(yy,2,OrderDate)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.