And then you better make sure you run the code more than once, even on a quiet system...
DECLARE @Year INT
SET @Year = 2008
SET STATISTICS IO ON
SET STATISTICS TIME ON
;WITH cteDates AS
(
SELECT DATEADD(yy,@Year-1900,0)+Number AS TheDate
FROM Master.dbo.spt_Values
WHERE Type = 'P'
AND Number <= 366
)
SELECT cd.TheDate, DATEPART(qq,TheDate) AS TheQuarter
FROM cteDates cd
WHERE YEAR(TheDate) = @Year
SET STATISTICS TIME OFF
PRINT REPLICATE('=',100)
SET STATISTICS TIME ON
SELECT DATEADD(yy,@Year-1900,0)+Number AS TheDate,
DATEPART(qq,DATEADD(yy,@Year-1900,0)+Number) AS TheQuarter
FROM Master.dbo.spt_Values
WHERE Type = 'P'
AND Number < 366
AND YEAR(DATEADD(yy,@Year-1900,0)+Number) = @Year
SET STATISTICS TIME OFF
SET STATISTICS IO OFF
--Jeff Moden
Change is inevitable... Change for the better is not.