• This will show you how to convert a range of dates into year/quarters. I'm also adding in the first and last date/time for each quarter. You should be able to use this to go forth and adapt to your requirements.

    declare @StartDate datetime

    set @StartDate = DateAdd(month, -1, DateAdd(year, DATEDIFF(year, 0, GetDate()), 0))

    -- See Jeff Moden's article

    -- The "Numbers" or "Tally" Table: What it is and how it replaces a loop.

    -- at http://www.sqlservercentral.com/articles/T-SQL/62867/.

    -- NOTE! A permanent tally table will always be MUCH faster

    -- than this inline one. See the above article to create your own!

    ;WITH

    Tens (N) AS (SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL

    SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL

    SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0),

    Tally (N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM Tens t1 CROSS JOIN Tens t2),

    Dates AS (SELECT MyDate = DateAdd(month, N, @StartDate) FROM Tally ),

    Quarters AS (SELECT MyDate, MyYear = YEAR(MyDate), Qtr = DatePart(quarter, MyDate)

    FROM Dates)

    SELECT MyYear, Qtr,

    QtrStartDate = MIN(MyDate),

    QtrEndDate = MAX(DateAdd(ms, -3, DateAdd(month, 1, MyDate)))

    FROM Quarters

    GROUP BY MyYear, Qtr

    ORDER BY MyYear, Qtr

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2