Convert Month Number to Month Name Function in SQL

前端 未结 30 1531
予麋鹿
予麋鹿 2020-11-22 11:53

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 a

30条回答
  •  囚心锁ツ
    2020-11-22 12:48

    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')     
    

提交回复
热议问题