27,580
社区成员
发帖
与我相关
我的任务
分享
create function gethours(@stime datetime,@etime datetime)
returns int
as
begin
declare @hstime int
declare @hetime int
declare @result int
select @hstime=datepart(hh,@stime)
select @hetime=datepart(hh,@etime)
if @hstime<8 and @hetime<17 and @hetime>8
set @result=@hetime-8
else if @hstime<8 and @hetime>17
set @result=8
else if @hstime<8 and @hetime<8
set @result=0
else if @hstime>17 and @hetime>17
set @result=0
else if @hstime>17 and @hetime<17 and @hetime>8
set @result=@hetime-8
else if @hstime>17 and @hetime<8
set @result=0
else
set @result=(cast(@hetime as int)- cast(@hstime as int))
return @result
end
go
create function gethours(@stime datetime,@etime datetime)
returns int
as
begin
declare @hstime nvarchar(30)
declare @hetime nvarchar(30)
declare @result int
select @hstime=Ltrim(datepart(hh,@stime))
select @hetime=Ltrim(datepart(hh,@etime))
if @hstime<8 and @hetime<17 and @hetime>8
set @result=@hetime-8
else if @hstime<8 and @hetime>17
set @result=8
else if @hstime<8 and @hetime<8
set @result=0
else if @hstime>17 and @hetime>17
set @result=0
else if @hstime>17 and @hetime<17 and @hetime>8
set @result=@hetime-8
else if @hstime>17 and @hetime<8
set @result=0
else
set @result=(cast(@hetime as int)- cast(@hstime as int))
return @result
end
go