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 2000 Forums
 Transact-SQL (2000)
 display month

Author  Topic 

krushnapanda
Starting Member

18 Posts

Posted - 2007-08-03 : 01:53:29
heloo dear
how to display this type of record by using SP
when i put the number of month then the result should display
the month name in words
like i put 3 , then result is display March

thanks

Thanks

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-08-03 : 02:29:17
declare @month as varchar(2)
set @month = '3'

select datename(month, @month + '/1/2007')





Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-03 : 03:09:02
or

select datename(month, dateadd(month,@month-1,0))

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-03 : 03:59:50
Or put "-1" directly into the third parameter?

SELECT DATENAME(MONTH, DATEADD(MONTH, @Month, -1))



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-03 : 04:39:26
quote:
Originally posted by Peso

Or put "-1" directly into the third parameter?

SELECT DATENAME(MONTH, DATEADD(MONTH, @Month, -1))



E 12°55'05.25"
N 56°04'39.16"


Yes if @Month is of INT datatype otherwise you need to cast it to int

Madhivanan

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

krushnapanda
Starting Member

18 Posts

Posted - 2007-08-03 : 04:49:33

THANKS
its work

quote:
Originally posted by jonasalbert20

declare @month as varchar(2)
set @month = '3'

select datename(month, @month + '/1/2007')





Want Philippines to become 1st World COuntry? Go for World War 3...



Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-03 : 05:42:19
quote:
Originally posted by madhivanan

Yes if @Month is of INT datatype otherwise you need to cast it to int
Same as your suggestion, I assume?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-03 : 05:51:03
quote:
Originally posted by Peso

quote:
Originally posted by madhivanan

Yes if @Month is of INT datatype otherwise you need to cast it to int
Same as your suggestion, I assume?



E 12°55'05.25"
N 56°04'39.16"


No. Thats the power of implicit convertion

--Mine
declare @month varchar(2)
set @month = '12'

select datename(month, dateadd(month,@month-1,0))

Go

Result
                               
------------------------------
December

(1 row(s) affected)

--Yours

declare @month varchar(2)
set @month = '12'

SELECT DATENAME(MONTH, DATEADD(MONTH, @Month, -1))
Result
Server: Msg 8116, Level 16, State 1, Line 5
Argument data type varchar is invalid for argument 2 of dateadd function.


Madhivanan

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

- Advertisement -