我将月份存储在SQL Server中为1,2,3,4,…12。我想把它们显示为一月,二月等。在SQL Server中有一个函数像MonthName(1) = 1月?如果可能的话,我尽量避免使用CASE语句。


当前回答

当然可以

select datename(M,GETDATE())

其他回答

我认为这是当你有月份号时,获得月份名称的最好方法

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

Or

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

用最好的方式

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

您可以使用内置的CONVERT函数

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

这将显示一个月的前3个字符(JAN,FEB等)。

SUBSTRING('JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ', (@intMonth * 4) - 3, 3)
select monthname(curdate());

OR

select monthname('2013-12-12');