Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- sms.csv
- declare @StartDate date = '2014-01-01';
- declare @EndDate date = '2020-01-01';
- WITH cte AS (
- SELECT IIF(DATEPART(Day, @StartDate) = 1, @StartDate, DATEADD(Month, DATEDIFF(Month, 0, @StartDate) + 1, 0)) AS myDate
- UNION ALL
- SELECT DATEADD(Month,1,myDate)
- FROM cte
- WHERE DATEADD(Month,1,myDate) < @EndDate
- )
- SELECT cast(myDate as DATE) as d,
- DATEPART(year, myDate) as y,
- count(s.s_id) as c
- FROM cte c
- inner join ops_sms s on year(s_sendDate) = year(c.myDate) and month(s_sendDate) = month(c.myDate)
- group by myDate
- order by myDate
- OPTION (MAXRECURSION 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement