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 2008 Forums
 Transact-SQL (2008)
 How to update date fields in a table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  02:19:12  Show Profile  Reply with Quote
hello all,

in my table i have 500000 records and 2 date fileds like

date of Eligibility Coverage END
2005-11-01 00:00:00.000 2005-12-31 00:00:00.000

now my requirement is

i need to update 5000 records and 5000 records etc; with

2011-11-01 00:00:00.000 etc

for all 50000 records

now in another column i need to update columns

with 3 month difference or 6 months diff or 1 year difference..basing on the date of Eligibility column

how i need to do this one???

P.V.P.MOhan

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 01/16/2013 :  02:27:00  Show Profile  Reply with Quote
May be this?

UPDATE TableName
SET CoverageEND =
CASE WHEN DateOfEligibility = value1 THEN dateadd( mm, 3 , DateOfEligibility )
WHEN DateOfEligibility = value2 THEN dateadd( mm, 6 , DateOfEligibility )
..........
END

--
Chandu
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 01/16/2013 :  13:50:48  Show Profile  Reply with Quote
If Bandi's solution doesn't work please provide DDL, DML and expected output. Here are some links that can help you prepare that:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
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.03 seconds. Powered By: Snitz Forums 2000