DECLARE @startmonth int = 1
DECLARE @endmonth int = 12
DECLARE @startyear int = 2012
DECLARE @endyear int = 2015
;
WITH monthlist AS
(
SELECT @startmonth AS m
UNION ALL
SELECT m+1 FROM monthlist WHERE m+1<=@endmonth
)
,yearlist AS
(
SELECT @startyear AS y
UNION ALL
SELECT y+1 FROM yearlist WHERE y+1<=@endyear
)
SELECT y,
m
FROM yearlist
CROSS JOIN monthlist
ORDER BY y,
m
OPTION (maxrecursion 1000)
No comments:
Post a Comment