Archive

Archive for August, 2016

List the Name of the Months Between Date Ranges in SQL Server

August 29, 2016 Leave a comment

Hi all,

Try this example to List the Name of the Months Between Date Ranges in SQL Server


DECLARE @sDate DATETIME = '20160301', @eDate DATETIME = '20160901';

;WITH cte AS
(
SELECT @sDate AS dates
UNION ALL
SELECT DATEADD(mm,1,c.dates)
FROM cte c
WHERE c.dates < @eDate
)
SELECT DATENAME(MM, dates)
FROM cte

Hope this helps

Good Luck.

Advertisements
Categories: SQL Server