日期:2014-05-18 浏览次数:20585 次
疯子,你搞的真复杂。。 declare @date1 datetime,@date2 datetime set @date1='2008-01-3' set @date2='2008-02-19' select datediff(dd,dateadd(dd,-6,dateadd(dd,7-datepart(dw,@date1),@date1)), dateadd(dd,-6,dateadd(dd,7-datepart(dw,@date2),@date2)))/7
------解决方案--------------------
如果是2000,返回天数 select count(1) from (select 0 as id union all select 1 as id ) t1, (select 0 as id union all select 2 as id ) t2, (select 0 as id union all select 4 as id ) t3, (select 0 as id union all select 8 as id ) t4, (select 0 as id union all select 16 as id ) t5, (select 0 as id union all select 32 as id ) t6, (select 0 as id union all select 64 as id ) t7, (select 0 as id union all select 128 as id ) t8, (select 0 as id union all select 256 as id ) t9, (select 0 as id union all select 512 as id ) t10 where t1.id+t2.id+t3.id+t4.id+t5.id+t6.ID+t7.id+t8.id+t9.id+t10.id<= datediff(day,'2008-01-01','2008-04-01') and (DATEPART(Weekday,dateadd(day,t1.id+t2.id+t3.id+t4.id+t5.id+t6.ID+t7.id+t8.id+t9.id+t10.id,'2008-01-01'))+@@DATEFIRST-1)%7 IN (0,6)