WITH CTE(DATE, Cnt)AS(SELECT DATEADD(DAY, -DAY(GETDATE()-1), GETDATE()), 1
UNION ALL
SELECT DATE+1, Cnt+1 FROM CTE WHERE Cnt < (SELECT DAY(DATEADD(DAY, -DAY(DATEADD(MM, 1, GETDATE())), DATEADD(MM, 1, GETDATE())))))
SELECT DATENAME(WEEKDAY, DATE) AS WEEKDAYS, cnt INTO #MaskTable FROM CTE OPTION(MAXRECURSION 30)
SELECT * FROM #MaskTable WHERE WEEKDAYS IN('Saturday', 'Sunday')
-----------------------------------------
Saturday 6
Sunday 7
Saturday 13
Sunday 14
Saturday 20
Sunday 21
Saturday 27
Sunday 28
UNION ALL
SELECT DATE+1, Cnt+1 FROM CTE WHERE Cnt < (SELECT DAY(DATEADD(DAY, -DAY(DATEADD(MM, 1, GETDATE())), DATEADD(MM, 1, GETDATE())))))
SELECT DATENAME(WEEKDAY, DATE) AS WEEKDAYS, cnt INTO #MaskTable FROM CTE OPTION(MAXRECURSION 30)
SELECT * FROM #MaskTable WHERE WEEKDAYS IN('Saturday', 'Sunday')
-----------------------------------------
Saturday 6
Sunday 7
Saturday 13
Sunday 14
Saturday 20
Sunday 21
Saturday 27
Sunday 28
No comments:
Post a Comment