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)
 How to get Month Name

Author  Topic 

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-01-13 : 19:51:49
Hi All,

I have a field showing month like 1,2,3

how i can show January for 1, February for 2 etc..
Thanks


mk_garg

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-13 : 19:54:11
[code]

SELECT MonthName =
CASE
WHEN MonthColumn = 1 THEN 'January'
WHEN MonthColumn = 2 THEN 'February'
etc...
END
[/code]

You'll probably want to put this into a UDF, so that it can be used in a SELECT in multiple queries.

Tara
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-01-13 : 19:55:31
Thanks for your help.
I am using Sql server 7.0.



mk_garg
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-13 : 20:21:54
Declare @myMonth int
Set @myMonth = 3

Select datename(month,convert(varchar,@myMonth)+'/1/2000')

Corey
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-13 : 20:24:19
Ahhhh yes. Make it a valid date, then get the month name. Never thought of doing it like that.

Tara
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-01-13 : 22:16:59
Thanks Corey

mk_garg
Go to Top of Page

VIG
Yak Posting Veteran

86 Posts

Posted - 2005-01-14 : 12:05:43
declare @m int
set @m=2
select datename(mm,dateadd(mm,@m-1,0)) MonthName
Go to Top of Page
   

- Advertisement -