Convert Month Number to Month Name Function in SQL

Saif Khan picture Saif Khan · Oct 9, 2008 · Viewed 1M times · Source

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.

Answer

leoinfo picture leoinfo · Oct 9, 2008

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 )

Or

Select DateName( month , DateAdd( month , @MonthNumber , -1 ) )