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 2005 Forums
 Transact-SQL (2005)
 Date Issue:

Author  Topic 

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-06-08 : 15:51:51
I have a columns

Date1 Date2
2006-09-30 2008-06-30
2006-09-30 2009-06-30

How to get :

Date1 Date2
2007-09-30 2008-06-30
2008-09-30 2009-06-30

So Date1 will changed only year part ( Date2 - 1 year).

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-08 : 15:54:41
Do you mean this?
update table
set date1=dateadd(year,-1,date2)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-06-08 : 15:58:39
update table
set year(date1) = year(date2)-1


But it doesn't work.
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-06-08 : 18:06:32
Got Answer myself:
update table
set date1 = DATEADD(MONTH,3,DATEADD(YEAR,-1,date2))
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-09 : 14:09:26
This will work correctly but are you sure the gap in months is always 3?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-09 : 14:17:10
update table
set date1 = DATEADD(MONTH,-9,date2)
Go to Top of Page
   

- Advertisement -