Returning Month Name in SQL Server Query

后端 未结 11 1013
情深已故
情深已故 2020-12-13 03:39

Using SQL Server 2008, I have a query that is used to create a view and I\'m trying to display a month\'s name instead of an integer.

11条回答
  •  悲哀的现实
    2020-12-13 03:44

    Without hitting db we can fetch all months name.

    WITH CTE_Sample1 AS
    (
        Select 0 as MonthNumber
    
        UNION ALL
    
        select MonthNumber+1 FROM CTE_Sample1
            WHERE MonthNumber+1<12
    )
    
    Select DateName( month , DateAdd( month , MonthNumber ,0 ) ) from CTE_Sample1
    

提交回复
热议问题