declare @s as datetime,@e as datetime set @s='20050101'set @e='20051231' select days/7*5+days%7- case when 6 between wd and wd+days%7-1 then 1 else 0 end-case when 7 between wd and wd+days%7-1 then 1 else 0 endfrom (select datediff(day,@s,@e)+1 as days, datepart(weekday,@s+@@datefirst-1) as wd)as d
http://bbs.csdn.net/topics/350142988