首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-29 
计算期间周末天数ms_sqlserver2000存储过程中如何获取给定的两个日期间共有几天周末?谢谢![解决办法]SQL c

计算期间周末天数
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) 

热点排行