如何解决插入SomeTable Exec StoredProcedure @ Param1 = @ param1,@ Param2 ='系统'未调用存储过程
我遇到的情况是,我需要分别运行存储过程以及需要从其他存储过程中调用。
让我介绍一下这种情况:我有3个存储过程,它们是从另一个存储过程中顺序调用的。就像在导入一些原始财务数据时从应用程序中调用第一个存储过程一样;从第一个存储过程调用第二个存储过程,在第二个存储过程中,有一个While
循环在其中调用了我的第三个存储过程。
2ND存储过程代码:
If @loopCount > 0
Begin
While(@i <= @loopCount)
Begin
Select @RecoString = '',@CompanyId = 0,@UserId = 0
Select @RecoString = MainRecord,@CompanyId = CompanyId,@UserId = UsersId
From #RecoData With (Nolock)
Where Id = @i
Order By Id
/* 3rd stored procedure is getting called - IF NO INSERT Statement */
----Exec USP_Temp @IsReco = 1,@ReconcileBy = 'system',@UserCompanyId = @UserCompanyId,@UserId = @UserId,@finalCollection = @RecoString
/* 3rd stored procedure is NOT getting called - IF INSERT Statement */
Insert Into dbo.ReconcileInsertUpdateLog(TransferDetailId,Msg,ReconcilationId,IsFutureTransferReconciled)
Exec dbo.USP_Temp @IsReco = 1,@CompanyId = @CompanyId,@finalCollection = @RecoString,@isAutoReconcile = 0
Set @i = @i + 1
End
End
3RD存储过程代码:
ALTER PROCEDURE dbo.USP_Temp
@IsReco Bit,@ReconcileBy Nvarchar(250),@UserCompanyId int,@UserId int,@finalCollection Nvarchar(Max) = '',@isAutoReconcile Bit = 0
AS
BEGIN
Set Nocount On;
Declare @TransName Varchar(100)
Select @TransName = 'USP_Temp'
Begin Try
Begin Transaction @TransName
Declare @Msg Nvarchar(Max) = '',@ParentReconcilationId Int = 0 -- 07.25.2019,@IsFutureTransferReconciled Int = 0 -- 07.25.2019
------------------------------------------------------------
-- Return result
------------------------------------------------------------
Insert Into dbo.TempReco(Comments)
Select 'Reached to USP_Temp 1 step ahead of Return final Result'
Select 1 As TransferDetailId,@Msg As Msg,@ParentReconcilationId As ReconcilationId -- 07.25.2019,@IsFutureTransferReconciled As IsFutureTransferReconciled -- 07.25.2019
Commit Transaction @TransName
GoTo EndLevel
End Try
Begin Catch
Set @Msg = Error_Message()
GoTo Error
End Catch
Error:
BEGIN
Insert Into dbo.TempReco(Comments) Select 'Reached to USP_Temp - Error Block'
Rollback Transaction @TransName
Select 0 As TransferDetailId,0 As ReconcilationId -- 07.25.2019,0 As IsFutureTransferReconciled -- 07.25.2019
END
EndLevel:
END
GO
看看第二个存储过程代码,如果在Exec SPName
之前没有insert into语句,并且在将存储过程与insoMetable before语句一起调用时又未调用存储过程,那么我评论了该代码是否有效。有人对此有想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。