Convert Month Number to Month Name Function in SQL

前端 未结 30 2049
予麋鹿
予麋鹿 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:33

    Just subtract the current month from today's date, then add back your month number. Then use the datename function to give the full name all in 1 line.

    print datename(month,dateadd(month,-month(getdate()) + 9,getdate()))
    

提交回复
热议问题