DECLARE @beginTime DATETIME ='2017-12-01'
DECLARE @endTime DATETIME ='2017-12-22'
set language N'Simplified Chinese'
;WITH c AS (--时间段内的每一天
select DATEADD(dd,number,@beginTime) as d
FROM master..spt_values
WHERE type='p' and DATEDIFF(dd,DATEADD(dd,number,@beginTime),@endTime)>0
)
,d AS (--应写的条数
SELECT SUM(CASE WHEN datename(weekday, d)='星期六' OR datename(weekday, d)='星期日' THEN 0 ELSE 1 END) shoTot
FROM c)
SELECT * FROM d