//Month Name and Month Number List between Two Date in SQL Server
SELECT MONTH(DATEADD(MONTH, x.number, '2013-05-31'))[MonthNo],
DATENAME(MONTH, DATEADD(MONTH, x.number, '2013-05-31'))[Month],
DATENAME(YEAR, DATEADD(MONTH, x.number, '2013-05-31'))[Year] ,
LEFT(DATENAME(MONTH, DATEADD(MONTH, x.number, '2013-05-31')),3) + ' ' + DATENAME(YEAR, DATEADD(MONTH, x.number, '2013-05-31')) [Name]
FROM master.dbo.spt_values x
WHERE x.type = 'P'
AND x.number <= DATEDIFF(MONTH, '2013-05-31', '2014-05-31')
SELECT MONTH(DATEADD(MONTH, x.number, '2013-05-31'))[MonthNo],
DATENAME(MONTH, DATEADD(MONTH, x.number, '2013-05-31'))[Month],
DATENAME(YEAR, DATEADD(MONTH, x.number, '2013-05-31'))[Year] ,
LEFT(DATENAME(MONTH, DATEADD(MONTH, x.number, '2013-05-31')),3) + ' ' + DATENAME(YEAR, DATEADD(MONTH, x.number, '2013-05-31')) [Name]
FROM master.dbo.spt_values x
WHERE x.type = 'P'
AND x.number <= DATEDIFF(MONTH, '2013-05-31', '2014-05-31')
No comments:
Post a Comment