The below code when run for the last day of the month it is giving me a week day count of 1 when it should be 0 - how can I fix it?
Declare @EndDate DateTime = '03-31-2021'
;WITH mycte AS (
SELECT @EndDate + 1 DateValue
UNION ALL
SELECT DateValue + 1
FROM mycte
WHERE DateValue < EOMONTH(@EndDate)
)
select
count(case when datepart(dw, DateValue) = 1 then 1 end) SunCount
, count(case when datepart(dw, DateValue) = 7 then 1 end) SatCount
, count(case when datepart(dw, DateValue) between 2 and 6 then 1 end) WeekCount
from mycte