Returning Month Name in SQL Server Query

后端 未结 11 969
情深已故
情深已故 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:59

    In SQL Server 2012 it is possible to use FORMAT(@mydate, 'MMMM') AS MonthName

    0 讨论(0)
  • 2020-12-13 04:00

    Select SUBSTRING (convert(varchar,S0.OrderDateTime,100),1,3) from your Table Name

    0 讨论(0)
  • 2020-12-13 04:01

    Have you tried DATENAME(MONTH, S0.OrderDateTime) ?

    0 讨论(0)
  • 2020-12-13 04:05

    basically this ...

    declare @currentdate datetime = getdate()
    select left(datename(month,DATEADD(MONTH, -1, GETDATE())),3)
    union all
    select left(datename(month,(DATEADD(MONTH, -2, GETDATE()))),3)
    union all
    select left(datename(month,(DATEADD(MONTH, -3, GETDATE()))),3)
    
    0 讨论(0)
  • 2020-12-13 04:06

    This will give you what u are requesting for:

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