I need a SELECT to return the previous 12 quarters.
I can join in the data i need once i figure out how to get started. I have a snippet i use in another piece to return the previous 12 hours for a report. i am thinking it would be something similar..
;Declare @Date datetime =getdate()
;WITH DatesPre AS
(
SELECT DATEPART(HOUR,DATEADD(HOUR,-1,@Date)) [Hour],
DATEADD(HOUR,-1,@Date+1) [Date], 1 Num
UNION ALL
SELECT DATEPART(HOUR,DATEADD(HOUR,-1,[Date])),
DATEADD(HOUR,-1,[Date]), Num+1
FROM DatesPre
WHERE Num < 12
)
SELECT [Hour]
FROM DatesPre
Here is sort of what i want to get to
