日期:2014-05-17 浏览次数:20535 次
select CAST(dbo.gethoursvs('2014-01-15 10:59:21.510','2014-01-15 13:13:16.167')AS nvarchar(10))
ALTER function [dbo].[gethoursvs](@stime datetime,@etime datetime)
returns decimal(15,2)
as
begin
declare @hstime decimal(15,2)
declare @hetime decimal(15,2)
declare @result decimal(15,2)
select @hstime=Ltrim(datepart(hh,@stime))
select @hetime=Ltrim(datepart(hh,@etime))
if (@hstime<8 and @hetime<17 and @hetime>7)
begin
set @result=cast(datediff(mi,8,@etime)/60.0 as decimal(15,2))
end
else if (@hstime<8 and @hetime>17)
begin
set @result=8
end
else if (@hstime<8 and @hetime<8)
begin
set @result=0
end
else if (@hstime>=17 and @hetime>=17)
begin
set @result=0
end
else if (@hstime>=17 and @hetime<17 and @hetime>=8)
begin
set @result=cast(datediff(mi,8,@etime)/60.0 as decimal(15,2))
end
else if (@hstime>=17 and @hetime<8)
begin
set @result=0
end
else if (@hs