Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Temp
- AS
- (
- SELECT n
- FROM (VALUES(0), (1), (2), (3), (4), (5), (6), (7), (8), (9)) Nums(n)
- ), Numbers
- AS
- (
- SELECT n = t2.n * 10 + t1.n + 0
- FROM Temp t1
- CROSS JOIN Temp t2
- ), FromToCTE
- AS
- (
- SELECT
- DATEADD(month, 1 * n, '2016-01-01') FromDate,
- DATEADD(day,-1,DATEADD(month, 1 *(n +1), '2016-01-01') ) ToDate
- FROM numbers
- WHERE (n + 1) <= 200
- ), range_date
- as
- (
- select CONVERT(VARCHAR(6), FromDate, 112) as MonthYear, FromDate,ToDate from FromToCTE
- where FromToCTE.ToDate < SYSDATETIME()
- )
- select * from range_date
- order by FromDate asc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement