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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to update date basing on another column date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

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

i have a table in which
date of Eligibility Coverage END

2011-12-03 00:00:00.000 2012-12-03 00:00:00.000
out put should be lkike
2011-12-03 00:00:00.000 2012-3-03 00:00:00.000

i need to update another column basing on date of this column
with 3 month difference or 6 months diff or 1 year difference..basing on the date of Eligibility column

how can i do this??

P.V.P.MOhan

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 01/16/2013 :  03:24:22  Show Profile  Reply with Quote
Duplicate http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=182138

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  03:57:39  Show Profile  Reply with Quote
No chandu...here i asked about single update query basing one column to another column

i worked out this issue

Thanks

P.V.P.MOhan
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 01/16/2013 :  04:10:48  Show Profile  Reply with Quote
How sholud you provided solution... post the solution. It may help others too

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  05:13:44  Show Profile  Reply with Quote
i have a table in which
1)i need to generate random dates for one column called date of Eligibility

2) basing on the date of Eligibility column i need to update 2 nd column with difference of 3months,4monthsetc....;

my first query :

UPDATE UserInsuranceBenfitType
SET DateOfEligibility = DATEADD(DAY, ABS(CHECKSUM(NEWID()) % 365), '2011-01-01')

my second query :
UPDATE UserInsuranceBenfitType_temp
SET CoverageEndsDate = dateADD(MM,3,DateOfEligibility)
where UserInsuranceBenfitTypeId between 1and 15000
UPDATE UserInsuranceBenfitType_temp
SET CoverageEndsDate = dateADD(MM,6,DateOfEligibility)
where UserInsuranceBenfitTypeId between 15000 and 25000

P.V.P.MOhan
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 01/16/2013 :  05:26:28  Show Profile  Reply with Quote
You can do 2nd update part as single UPDATE statement

UPDATE UserInsuranceBenfitType_temp
SET CoverageEndsDate =
CASE WHEN UserInsuranceBenfitTypeId between 1and 15000 THEN dateADD(MM,3,DateOfEligibility)
WHEN UserInsuranceBenfitTypeId between 15001 and 25000 THEN coverageEndsDate = dateADD(MM,6,DateOfEligibility)
END




--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  07:03:01  Show Profile  Reply with Quote
thanks chandu

P.V.P.MOhan
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 01/16/2013 :  07:25:04  Show Profile  Reply with Quote
quote:
Originally posted by mohan123

thanks chandu

P.V.P.MOhan


Welcome

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