Here is another option. Use a CTE to define the months of the quarter and then join to it to determine the quarter:
WITH Quarters AS (
SELECT Q = 'Q1', MonthBegin = 1, MonthEnd = 3 UNION
SELECT Q = 'Q2', MonthBegin = 4, MonthEnd = 6 UNION
SELECT Q = 'Q3', MonthBegin = 7, MonthEnd = 9 UNION
SELECT Q = 'Q4', MonthBegin = 10, MonthEnd = 12
)
SELECT
[Year] = DATEPART(yyyy, CONVERT(DATETIME, Dates.[date])),
[Quarter] = CONVERT(VARCHAR(4), DATEPART(yyyy, CONVERT(DATETIME, Dates.[date]))) + '-' + q.Q
FROM
(VALUES
('20080102'),
('20070821')
) AS Dates ([date])
INNER JOIN Quarters q ON
DATEPART(m, CONVERT(DATETIME, Dates.[date])) >= q.MonthBegin AND
DATEPART(m, CONVERT(DATETIME, Dates.[date])) <= q.MonthEnd;
Returns:
Year Quarter
----- ----------
2008 2008-Q1
2007 2007-Q3
SQL Fiddle
Handle column type of int (04/23/2014):
WITH Quarters AS (
SELECT Q = 'Q1', MonthBegin = 1, MonthEnd = 3 UNION
SELECT Q = 'Q2', MonthBegin = 4, MonthEnd = 6 UNION
SELECT Q = 'Q3', MonthBegin = 7, MonthEnd = 9 UNION
SELECT Q = 'Q4', MonthBegin = 10, MonthEnd = 12
)
SELECT
[Year] = DATEPART(yyyy, CONVERT(DATETIME, CONVERT(VARCHAR(8), Dates.[date]))),
[Quarter] = CONVERT(VARCHAR(4), DATEPART(yyyy, CONVERT(DATETIME, CONVERT(VARCHAR(8), Dates.[date])))) + '-' + q.Q
FROM
(VALUES
(20080102),
(20070821)
) AS Dates ([date])
INNER JOIN Quarters q ON
DATEPART(m, CONVERT(DATETIME, CONVERT(VARCHAR(8), Dates.[date]))) >= q.MonthBegin AND
DATEPART(m, CONVERT(DATETIME, CONVERT(VARCHAR(8), Dates.[date]))) <= q.MonthEnd;