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)
 how to update month?

Author  Topic 

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-08-20 : 06:21:14
Hello

i have a table with two cols...

id date
1 2008-08-20
2 2008-09-21
3 2008-01-01

how can i update the month to december.

Thanks in advance


Thanks

Zakeer Sk

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 06:25:52

Select id, dateadd(month,12-month(date),date) from table

Madhivanan

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

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-08-20 : 07:56:16
thanks madhivanan

I wrote a sp like this.

create proc datechange
(
@Month int
)
as
begin
update sample set date=dateadd(month,@month-month(date),date)
end

Using this sp I can pass int as parameter and I can able update the table. If I pass month name instead of int.can I able to update.

If I give month names as input. can I get the output as

2008-November-20
2008-January-20
-------------
-
--
-
-
-





Thanks

Zakeer Sk

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 08:19:34

declare @month varchar(10)
set @month='december'
select dateadd(month,month(cast(@month+' 2008' as datetime))-month(getdate()),getdate())


Madhivanan

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

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-08-20 : 08:49:04
gr8...thanks alot

have a gr8 day.........

Thanks

Zakeer Sk

Go to Top of Page
   

- Advertisement -