Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
records as follows;


select * from co_batch_master;


Name course startdate enddate

A RM 17 Jun 2013 18 Aug 2013
B REO 21 Aug 2013 14 Dec 2013
C REO 21 Aug 2013 14 Dec 2013
D REO 21 Aug 2013 14 Dec 2013
E REO 21 Aug 2013 14 Dec 2013


from the above query i want to add 5 years at the end date of each course.


My required output as follows


Name course startdate enddate expirydate

A RM 17 Jun 2013 18 Aug 2013 18 Aug 2018
B REO 21 Aug 2013 14 Dec 2013 14 Dec 2018
C REO 21 Sep 2013 19 Dec 2013 19 Dec 2018
D REO 21 Oct 2013 29 Dec 2013 29 Dec 2018
E REO 21 Nov 2013 14 Dec 2013 14 Dec 2018


for the above output how can i write the query.

please help me.

Rgds,
Narasiman P.
Posted

Hi,


Try this

SQL
UPDATE
   table
SET
    c.expirydate= DATEADD(yy, 5,r.enddate),
    
FROM
     co_batch_master c
INNER JOIN
    co_batch_master r
ON
    c.id = r.id</pre>


Note: 'id' is your table primary key.

---S.P
 
Share this answer
 
v5
Hi ,

Your query would be like that
SQL
Select *, DATEADD(yy, 5, ENDDATE) as ExpiryDate from co_batch_master


Refer below
http://msdn.microsoft.com/en-us/library/aa258267(SQL.80).aspx[^]
 
Share this answer
 
Comments
Member 11342869 27-Jan-15 5:43am    
Hi,
Your query was used to select and view the date in ExpiredDate only but i need to store the value in the Expire date itself. Please help me for that..
Thanks in advance.
Use
SQL
DATEADD(YY,5,enddate)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900