2017-10-20 51 views
0

首先我需要檢查一下,如果spOBJ_CopyInspectiontask有任何錯誤,如果沒有錯誤,那麼就進入插入語句。程序內程序調用

DECLARE @tblSystemId TABLE 
        (
         OldSysId int, NewSysId int, 
         OldTaskId int, NewTaskId int, 
         TaskObjectIds varchar(max) null 
        ); 

INSERT INTO @tblSystemId (OldSysId , NewSysId, OldTaskId, NewTaskId, TaskObjectIds)    
    EXEC dbo.spOBJ_CopyInspectiontask @UserId, @TargetCustomerId, @TargetContractId, @TargetSiteId, @SourceCustomerId, @OldTaskId, @SystemName, @Checkall, @CopyReports, @Return OUTPUT, @ObjectIds OUTPUT; 

我該如何檢查?

+0

默認情況下,在插入MS SQL Server的隱式事務應啓動。因此,如果在調用dbo.spOBJ_CopyInspectiontask期間發生任何錯誤,整個事務將被回滾,並且沒有行通過此語句插入到@tblSystemId中。爲什麼你;我不喜歡上面描述的默認行爲? –

回答

2

也許你想要一個try/catch塊:

BEGIN TRY 
    INSERT INTO @tblSystemId (OldSysId , NewSysId, OldTaskId, NewTaskId,TaskObjectIds)    
     EXEC dbo.spOBJ_CopyInspectiontask @UserId,@TargetCustomerId, @TargetContractId, @TargetSiteId, 
      @SourceCustomerId, @OldTaskId, @SystemName, @Checkall, @CopyReports, @Return OUTPUT, @ObjectIds OUTPUT; 
END TRY 
BEGIN CATCH 
    -- do something here in the event of failure 
END CATCH; 
+0

讓我試試...謝謝 –

+0

工作正常。謝謝 –