当前位置: 代码迷 >> Sql Server >> 计算期间周末天数,该怎么解决
  详细解决方案

计算期间周末天数,该怎么解决

热度:100   发布时间:2016-04-27 15:19:46.0
计算期间周末天数
ms_sqlserver2000存储过程中

如何获取给定的两个日期间共有几天周末?

谢谢!

------解决方案--------------------
SQL code
疯子,你搞的真复杂。。declare @date1 datetime,@date2 datetimeset @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
------解决方案--------------------
SQL code
如果是2000,返回天数select count(1)from  (select 0 as idunion all select 1 as id ) t1,(select 0 as idunion all select 2 as id ) t2,(select 0 as idunion all select 4 as id ) t3,(select 0 as idunion all select 8 as id ) t4,(select 0 as idunion all select 16 as id ) t5,(select 0 as idunion all select 32 as id ) t6,(select 0 as idunion all select 64 as id ) t7,(select 0 as idunion all select 128 as id ) t8,(select 0 as idunion all select 256 as id ) t9,(select 0 as idunion 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)
  相关解决方案