本文介绍了EXECUTE之后的事务计数表示BEGIN和COMMIT语句的数量不匹配。先前的计数= 0,当前计数= 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我收到此错误 任何人都可以告诉我这里的错误我是sp的新手 提前感谢 EXECUTE后的事务计数表示BEGIN和COMMIT语句的数量不匹配。以前的计数= 0,当前计数= 1 代码: 开始尝试 BEGIN TRAN IF(@ iHId = 0) 如果不存在(选择HDR.AOHId FROM dbo.tblXHdrApplicationOptions HDR INNER JOIN dbo.tblXDtlApplicationSuper DTL ON HDR。 AOHId = DTL.ASDHId 其中DTL.ASDChildName=@strChildName) BEGIN INSERT INTO dbo.tblXHdrApplicationOptions(AOHRootIndex,AOHRootName,AOHUser, AOHDateTime) VALUES(@ iRootIndx,@ strRootName,@ strUserName,GETDATE()) DECLARE @ iAOHId INT SET @iAOHId = SCOPE_IDENTITY (); INSERT INTO dbo.tblXDtlApplicationSuper(ASDHId,ASDChildName,ASDIsEOMYN,ASDIsEachPayYN,ASDYearsIfEomIsYes,ASDUser,ASDDateTime) VALUES(@ iAOHId,@ strChildName,@ bIsEomYN,@ bEachPayYN,@ strYearifEOMisYes,@ ssUserName,GETDATE()) DECLARE @ASDHId INT SET @ASDHId = SCOPE_IDENTITY(); INSERT INTO tblXDtlApplicationSuperdetails(ASDDHID,ASDDChildName,ASDDMonthCode,ASDDEOMDate,ASDDUser, ASDDDateTime) VALUES(@ iAOHId,@ strChildName,@ strMonthCode,@ dtpEOMDate,@ strUserName,GETDATE()) DECLARE @ASDDHID INT SET @iAOHId = SCOPE_IDENTITY() COMMIT TRAN 返回0 结束 ELSE IF存在(选择HDR.AOHId来自dbo.tblXHdrApplicationOptions HDR INNER JOIN dbo.tblXDtlApplicationSuper DTL ON HDR.AOHId = DTL.ASDHId 其中DTL.ASDChildName=@strChildName) - BEGIN 更新dbo.tblXHdrApplicationOptions SET AOHDateTime = GETDATE(); UPDATE dbo.tblXDtlApplicationSuper SET ASDIsEOMYN = @ bIsEomYN,ASDIsEachPayYN = @ bEachPayYN, ASDYearsIfEomIsYes = @ strYearifEOMisYes,ASDUser = @strUserName,ASDDateTime = GETDATE() WHERE ASDHId = @iHId; UPDATE tblXDtlApplicationSuperdetails SET ASDDChildName = @ strChildName,ASDDMonthCode = @ strMonthCode, ASDDEOMDate = @ dtpEOMDate ,ASDDUser = @ strUserName,ASDDDateTime = GETDATE()WHERE ASDDHID = @ iAOHId COMMIT TRAN RETURN 0 结束 结束尝试 BEGIN CATCH ROLLBACK TRAN; DECLARE @ErrorMessage NVARCHAR(4000), @ErrorSeverity INT,@ ErrorState INT; SET @ErrorMessage =' - 1'+ ERROR_MESSAGE(); SET @ErrorSeverity = ERROR_SEVERITY(); SET @ErrorState = ERROR_STATE(); RAISERROR(@ ErrorMessage,@ ErrorSeverity,@ ErrorState); END CATCH i am getting this errorcan any one tell me what's the mistake here i am new to sp'sthanks in advanceTransaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1Code:BEGIN TRYBEGIN TRANIF( @iHId =0)IF not exists(select HDR.AOHId FROM dbo.tblXHdrApplicationOptions HDR INNER JOIN dbo.tblXDtlApplicationSuper DTL ON HDR.AOHId = DTL.ASDHId where DTL.ASDChildName=@strChildName )BEGININSERT INTO dbo.tblXHdrApplicationOptions (AOHRootIndex, AOHRootName,AOHUser, AOHDateTime) VALUES (@iRootIndx, @strRootName,@strUserName, GETDATE())DECLARE @iAOHId INTSET@iAOHId = SCOPE_IDENTITY();INSERT INTO dbo.tblXDtlApplicationSuper ( ASDHId , ASDChildName,ASDIsEOMYN,ASDIsEachPayYN,ASDYearsIfEomIsYes,ASDUser,ASDDateTime)VALUES(@iAOHId, @strChildName,@bIsEomYN,@bEachPayYN,@strYearifEOMisYes, @strUserName, GETDATE())DECLARE @ASDHId INTSET@ASDHId = SCOPE_IDENTITY();INSERT INTO tblXDtlApplicationSuperdetails (ASDDHID, ASDDChildName,ASDDMonthCode, ASDDEOMDate,ASDDUser,ASDDDateTime)VALUES (@iAOHId, @strChildName,@strMonthCode, @dtpEOMDate,@strUserName,GETDATE())DECLARE @ASDDHID INTSET@iAOHId = SCOPE_IDENTITY()COMMIT TRANRETURN 0 ENDELSEIF exists(select HDR.AOHId FROM dbo.tblXHdrApplicationOptions HDR INNER JOIN dbo.tblXDtlApplicationSuper DTL ON HDR.AOHId = DTL.ASDHId where DTL.ASDChildName=@strChildName )--BEGIN UPDATE dbo.tblXHdrApplicationOptions SET AOHDateTime = GETDATE(); UPDATE dbo.tblXDtlApplicationSuper SET ASDIsEOMYN=@bIsEomYN ,ASDIsEachPayYN=@bEachPayYN , ASDYearsIfEomIsYes=@strYearifEOMisYes ,ASDUser = @strUserName, ASDDateTime = GETDATE() WHERE ASDHId = @iHId ; UPDATE tblXDtlApplicationSuperdetails SET ASDDChildName=@strChildName,ASDDMonthCode=@strMonthCode,ASDDEOMDate=@dtpEOMDate,ASDDUser=@strUserName,ASDDDateTime=GETDATE() WHERE ASDDHID=@iAOHIdCOMMIT TRANRETURN 0 ENDEND TRYBEGIN CATCHROLLBACK TRAN;DECLARE @ErrorMessage NVARCHAR(4000), @ErrorSeverity INT,@ErrorState INT; SET @ErrorMessage ='-1'+ERROR_MESSAGE(); SET @ErrorSeverity = ERROR_SEVERITY(); SET @ErrorState = ERROR_STATE(); RAISERROR(@ErrorMessage,@ErrorSeverity,@ErrorState); END CATCH推荐答案 这篇关于EXECUTE之后的事务计数表示BEGIN和COMMIT语句的数量不匹配。先前的计数= 0,当前计数= 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 23:03