declare @b datetime,@e datetime
set @b = '2003-12-20'
set @e = '2004-01-21'
select datediff(week,@b,@e)
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 1 then 0 else 1 end - case when datepart(weekday,@e) >= 1 then 0 else 1 end as 周日数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 2 then 0 else 1 end - case when datepart(weekday,@e) >= 2 then 0 else 1 end as 周一数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 3 then 0 else 1 end - case when datepart(weekday,@e) >= 3 then 0 else 1 end as 周二数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 4 then 0 else 1 end - case when datepart(weekday,@e) >= 4 then 0 else 1 end as 周三数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 5 then 0 else 1 end - case when datepart(weekday,@e) >= 5 then 0 else 1 end as 周四数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 6 then 0 else 1 end - case when datepart(weekday,@e) >= 6 then 0 else 1 end as 周五数
,datediff(week,@b,@e) + case when datepart(weekday,@b) > 7 then 0 else 1 end - case when datepart(weekday,@e) >= 7 then 0 else 1 end as 周六数
转载于:https://www.cnblogs.com/jcomet/archive/2009/10/27/1590863.html