如何根据轮班开始和结束来计算员工的工作时间为工作日,应为十进制(09:00至17:30)为8.5小时。有效轮班的其他示例是08:00-16:00、09:00-17:00和08:00-20:00。无需扣除任何午休时间
我已经尝试过该功能,但需要使用交叉应用吗?有任何建议吗
Create function[dbo.][WorkingHours]
(
@StartDate datetime,
@EndDate `datetime,
@StartTime time,
@EndTime time
)
Returns Table
as
Return
(
select convert(varchar,sum(datediff(minute,A.startDatetime,A.EndDatetime))/60)+':'+
convert(varchar,sum(datediff(minute,A.startDatetime,A.EndDatetime))%60) as TotalWorkedHours
from
(
select[calenderdate]as Date,
convert(datetime,[calenderdate])+''+@Starttime as StartDatetime,
convert (datetime,[calenderdate])+''+@EndTime as EndDatetime
from [dbo].[Date] D
where WeekDay not in(1,7)
and D.CalenderDate between @StartDate and @EndDate and holiday = '0'
)A
)