Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. -- sms.csv
  2. declare @StartDate date = '2014-01-01';
  3. declare @EndDate date = '2020-01-01';
  4. WITH cte AS (
  5. SELECT IIF(DATEPART(Day, @StartDate) = 1, @StartDate, DATEADD(Month, DATEDIFF(Month, 0, @StartDate) + 1, 0)) AS myDate
  6. UNION ALL
  7. SELECT DATEADD(Month,1,myDate)
  8. FROM cte
  9. WHERE DATEADD(Month,1,myDate) < @EndDate
  10. )
  11. SELECT cast(myDate as DATE) as d,
  12. DATEPART(year, myDate) as y,
  13. count(s.s_id) as c
  14. FROM cte c
  15. inner join ops_sms s on year(s_sendDate) = year(c.myDate) and month(s_sendDate) = month(c.myDate)
  16. group by myDate
  17. order by myDate
  18. OPTION (MAXRECURSION 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement