日期:2014-05-18  浏览次数:20522 次

请大神指点~~
计算有效工作时间( 单位 :分钟 )

方式:存储过程或其他形式(跪求 附注释)

测试时间:开始 2011-01-01  
  结束 2011-12-31
工作时间
--上午
09:00——12:00
--下午
13:30——18:00
--休息时间
12:00——13:30


*附
--1
计算的开始、结束时间也会在上午、下午、休息时间段内
当天
09:00以前 开始 视为 09:00
12:00以后 13:30之前 开始 视为 13:30

18:00以后 结束 视为 18:00
12:00以后 13:30之前 结束 视为 12:00
--2
除去自定义节假日表 bz_workday 

bz_workday (hdate datetime,name char(20))

*部分内容 




hdate name 
2011-01-01 00:00:00.000 元旦  
2011-01-02 00:00:00.000 元旦  
2011-01-03 00:00:00.000 元旦  
2011-01-08 00:00:00.000 星期六  
2011-01-09 00:00:00.000 星期日  
2011-01-15 00:00:00.000 星期六  
2011-01-16 00:00:00.000 星期日  
2011-01-22 00:00:00.000 星期六  
2011-01-23 00:00:00.000 星期日  
2011-01-29 00:00:00.000 星期六  
2011-01-30 00:00:00.000 星期日  
2011-02-01 00:00:00.000 春节  
2011-02-02 00:00:00.000 春节  
2011-02-03 00:00:00.000 春节  
2011-02-04 00:00:00.000 春节  
2011-02-05 00:00:00.000 春节  
2011-02-06 00:00:00.000 春节  
2011-02-07 00:00:00.000 春节  
2011-02-08 00:00:00.000 春节  
2011-02-12 00:00:00.000 星期六  
2011-02-13 00:00:00.000 星期日  
2011-02-19 00:00:00.000 星期六  
2011-02-20 00:00:00.000 星期日  
2011-02-26 00:00:00.000 星期六  
2011-02-27 00:00:00.000 星期日  


------解决方案--------------------
SQL code
create table bz_workday (hdate datetime,name char(20))
insert into bz_workday select '2011-01-01 00:00:00.000','元旦'   
insert into bz_workday select '2011-01-02 00:00:00.000','元旦'   
insert into bz_workday select '2011-01-03 00:00:00.000','元旦'   
insert into bz_workday select '2011-01-08 00:00:00.000','星期六'   
insert into bz_workday select '2011-01-09 00:00:00.000','星期日'   
insert into bz_workday select '2011-01-15 00:00:00.000','星期六'   
insert into bz_workday select '2011-01-16 00:00:00.000','星期日'   
insert into bz_workday select '2011-01-22 00:00:00.000','星期六'   
insert into bz_workday select '2011-01-23 00:00:00.000','星期日'   
insert into bz_workday select '2011-01-29 00:00:00.000','星期六'   
insert into bz_workday select '2011-01-30 00:00:00.000','星期日'   
insert into bz_workday select '2011-02-01 00:00:00.000','春节' 
insert into bz_workday select '2011-02-02 00:00:00.000','春节'  
insert into bz_workday select '2011-02-03 00:00:00.000','春节'   
insert into bz_workday select '2011-02-04 00:00:00.000','春节'   
insert into bz_workday select '2011-02-05 00:00:00.000','春节'   
insert into bz_workday select '2011-02-06 00:00:00.000','春节'   
insert into bz_workday select '2011-02-07 00:00:00.000','春节'   
insert into bz_workday select '2011-02-08 00:00:00.000','春节'   
insert into bz_workday select '2011-02-12 00:00:00.000','星期六'   
insert into bz_workday select '2011-02-13 00:00:00.000','星期日'   
insert into bz_workday select '2011-02-19 00:00:00.000','星期六'   
insert into bz_workday select '2011-02-20 00:00:00.000','星期日'   
insert into bz_workday select '2011-02-26 00:00:00.000','星期六'   
insert into bz_workday select '2011-02-27 00:00:00.000','星期日'
go
select COUNT(*)*7.5*60 worktime  --根据楼主的标准,每天工作时间为7.5小时
from master..spt_values a where type='p' and DATEADD(d,number,'2011-01-01')<'2012-01-01'
and not exists(select 1 from bz_workday where hdate=DATEADD(d,number,'2011-01-01'))
/*
worktime
---------------------------