Monday 28 March 2016

Get Month Name in SQL Server


WITH R(N) AS
(
    SELECT 0
    UNION ALL
    SELECT N+1
    FROM R
    WHERE N < 11
)

SELECT N,LEFT(DATENAME(MONTH,DATEADD(MONTH,-N,GETDATE())),12) AS [month]
FROM R order by N Desc