tags:

views:

41612

answers:

6

Hi, I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL Server like MonthName(1) = January? I am trying to avoid a CASE statement, if possible.

Thanks

Edit ~ I am on SQL Server 2005, if this makes a difference.

+3  A: 

A little hacky but should work:

SELECT DATENAME(month, DATEADD(month, @mydate-1, CAST('2008-01-01' AS datetime)))
Alexander Kojevnikov
+1  A: 

In some locales like Hebrew, there are leap months dependant upon the year so to avoid errors in such locales you might consider the following solution:

SELECT DATENAME(month, STR(YEAR(GETDATE()), 4) + REPLACE(STR(@month, 2), ' ', '0') + '01')
Jim Burger
+9  A: 

I think this is the best way to get the month name when you have the month number

Select DateName( month , DateAdd( month , @MonthNumber , 0 ) - 1 )
leoinfo
for readability purposes I would actually write it like this: Select DateName( month , DateAdd( month , @MonthNumber - 1 , '1900-01-01' ) )
Valentino Vranken
A: 

You can use the inbuilt CONVERT function

select CONVERT(varchar(3), Date, 100) as Month from MyTable.

This will display first 3 characters of month (JAN,FEB etc..)

A: 

SELECT DATENAME(month, GETDATE()) AS 'Month Name'

Dharamvir