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
 General SQL Server Forums
 New to SQL Server Programming
 How to UPDATE Year

Author  Topic 

apantig
Posting Yak Master

104 Posts

Posted - 2006-01-12 : 00:52:55
Hi guys,

Thanks for the recent help.

Now, how can I update the YEAR?

Sample Data

11-23-1903
11-20-1903
01-04-1903

Thank you.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-12 : 00:59:53
quote:
Originally posted by apantig

Hi guys,

Thanks for the recent help.

Now, how can I update the YEAR?

Sample Data

11-23-1903
11-20-1903
01-04-1903

Thank you.


Do you want to update them to 2006?
What is your expected result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-12 : 01:01:23
you mean change all the year to a diff year or something else ?

create table #temp
(
dt datetime
)

delete #temp
insert into #temp
select '11-23-1903' union all
select '11-20-1903' union all
select '01-04-1903'

declare @year int

select @year = 2006

select * from #temp

update #temp
set dt = dateadd(year, @year - 1900, dateadd(year, 1900 - year(dt), dt))

select * from #temp

drop table #temp



-----------------
'KH'

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Go to Top of Page

apantig
Posting Yak Master

104 Posts

Posted - 2006-01-12 : 01:02:15
The user input was wrong. Instead of 2003, they input 1903. These records came from data migration. I expect year 2003.

Thank you
Go to Top of Page

apantig
Posting Yak Master

104 Posts

Posted - 2006-01-12 : 01:14:33
Khtan,

Thank you. It works now and records are updated.


Thanks and more power.
Go to Top of Page

apantig
Posting Yak Master

104 Posts

Posted - 2006-01-12 : 01:15:35
Khtan,

Thank you. It works now and records are updated.


Thanks and more power.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-12 : 01:21:52
You are welcome

You are welcome

-----------------
'KH'

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Go to Top of Page
   

- Advertisement -