过程调用内部过程

时间:2017-10-20 09:54:51

标签: sql sql-server stored-procedures

首先,我需要检查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;

我该怎么检查?

1 个答案:

答案 0 :(得分: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;