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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to update date fields in a table

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-01-16 : 02:19:12
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-01-16 : 02:27:00
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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-01-16 : 13:50:48
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
   

- Advertisement -