Create procedure UserIsonLine
(
@OperatorName varchar(10),
@IsOnLine int out
)
as
declare @busy int
declare @State int
begin
set nocount on
begin tran
select @busy = case when abs(datediff(second,LoginTime,getdate()))<120 then 1 else 0 end,
@State = isnull(IsOnline,0)
from t_Operator with(tablockx) where OperatorName=@OperatorName
if (@@error <> 0) goto error1
if (@busy = 1) and (@State = 1)
set @IsOnLine = 1
else
begin
set @IsOnLine = 0
update t_Operator with(tablockx) set LoginTime = getdate(),IsOnLine = 1 where OperatorName=@OperatorName
if (@@error <> 0) goto error1
end
commit tran
set nocount off
return 0
end
error1:
begin
print '出错0001'
set nocount off
rollback tran
end