Returning Month Name in SQL Server Query

后端 未结 11 968
情深已故
情深已故 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:43
    DECLARE @iMonth INT=12
    SELECT CHOOSE(@iMonth,'JANUARY','FEBRUARY','MARCH','APRIL','MAY','JUNE','JULY','AUGUST','SEPTEMBER','OCTOBER','NOVEMBER','DECEMBER')
    
    0 讨论(0)
  • 2020-12-13 03:44

    Change:

    CONVERT(varchar(3), DATEPART(MONTH, S0.OrderDateTime) AS OrderMonth
    

    To:

    CONVERT(varchar(3), DATENAME(MONTH, S0.OrderDateTime)) AS OrderMonth
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-13 03:50
    SELECT MONTHNAME( `col1` ) FROM `table_name` 
    
    0 讨论(0)
  • 2020-12-13 03:54

    Try this:

    SELECT LEFT(DATENAME(MONTH,Getdate()),3)
    
    0 讨论(0)
  • 2020-12-13 03:57

    This will give you the full name of the month.

    select datename(month, S0.OrderDateTime)
    

    If you only want the first three letters you can use this

    select convert(char(3), S0.OrderDateTime, 0)
    
    0 讨论(0)
提交回复
热议问题