The code is given below with which we get the list of months between a particular quarter.
Script
- DECLARE @AnyDate DATETIME
- SET @AnyDate = GETDATE()
-
- DECLARE @StartDate DATETIME,
- @EndDate DATETIME;
- select @StartDate = DATEADD(q, DATEDIFF(q, 0, @AnyDate), 0)
-
- select @EndDate = DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, @AnyDate) + 1, 0));
-
-
- SELECT DATENAME(MONTH, DATEADD(MONTH, x.number, @StartDate)) AS MonthName
- FROM master.dbo.spt_values x
- WHERE x.type = 'P'
- AND x.number <= DATEDIFF(MONTH, @StartDate, @EndDate);
Output
Thanks.