Just want to add that this is what I did after I did a bit of googling. I was thinking of some more efficient way but I think this is sufficient for my purpose. The first part is to populate a date table, the second part to calculate the quarter range.
DECLARE @StartDate SMALLDATETIME
DECLARE @EndDate SMALLDATETIME
SET @StartDate = '1/1/2011'
SET @EndDate = '12/31/2011'
-- creates a date table, not needed if there is one already
DECLARE @date TABLE ( [date] SMALLDATETIME )
DECLARE @offset INT
SET @offset = 0
WHILE ( @offset < DATEDIFF(dd, @StartDate, DATEADD(dd, 1, @EndDate)) )
BEGIN
INSERT INTO @date ( [date] )
VALUES ( DATEADD(dd, @offset, @StartDate) )
SELECT @offset = @offset + 1
END ;
WITH dateCTE
AS ( SELECT ROW_NUMBER() OVER ( ORDER BY [date] ASC ) AS qID ,
[date] AS qStart ,
CASE WHEN DATEADD(dd, -1, DATEADD(q, 1, [date])) > @EndDate
THEN @EndDate
ELSE DATEADD(dd, -1, DATEADD(q, 1, [date]))
END AS qEnd
FROM @date
WHERE [date] = @StartDate
OR ( DATEDIFF(mm, @StartDate, [date]) % 3 = 0
AND DATEPART(dd, [date]) = DATEPART(dd,
@StartDate)
)
)