IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_execute_job_task_60]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_execute_job_task_60]
GO
CREATE procedure [dbo].[mps_execute_job_task_60]
as
begin

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  declare @res int 
  exec checktask 5,@res output 
  if (@res=1) return  
  
  declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for
  select wt_id,wt_task   from mps_job_task where wt_begin<=getdate() and wt_flag<=3 and wt_interval>=60 
  order by wt_flag 
  open status1
  declare @sql nvarchar(4000) 
  declare @taskid int 
  FETCH NEXT FROM status1 INTO @taskid,@sql
  WHILE (@@FETCH_STATUS = 0)
  BEGIN
  set @sql = isnull(@sql,'') 
  if (len(@sql)>10) 
  begin
  BEGIN TRY 
BEGIN TRAN 
  update mps_job_task set wt_flag = wt_flag + 1 where wt_id=@taskid 
  exec sp_executesql @sql ,N'@taskid int',@taskid 
  update mps_job_task set wt_flag = 0 where wt_id=@taskid 
  COMMIT TRAN -------提交事务
END TRY-----------结束捕捉异常
BEGIN CATCH------------有异常被捕获
IF @@TRANCOUNT > 0---------------判断有没有事务
BEGIN
ROLLBACK TRAN----------回滚事务
END 
insert into mps_task_error(tske_type,tske_tskid,tske_number,tske_severity,tske_state,tske_procedure,tske_line,tske_message)
SELECT 'job60',@taskid,ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ERROR_PROCEDURE(),
ERROR_LINE(),ERROR_MESSAGE() 
END CATCH--------结束异常处理
  end
   FETCH NEXT FROM status1 INTO @taskid,@sql
  END
  CLOSE status1
DEALLOCATE status1 
exec finishedtask 5
end