开发者社区> 问答> 正文

SQL Server 2008事务数后执行显示数量不匹配的开始和提交语句。 之前的数= 0,当前数=

错误出现在我取消后回滚事务行OutputID = 1

我想回滚事务如果任何序列号不匹配一个特定的OrderID。

你能请帮我我的事务。 开始和提交语句看起来对我好。 验证所有开始提交语句通过proc

Alter proc dbo.UpdatePartnerSerialNumbersBatchDetails
@OrderID int,
@SerialNumberDetails xml=null,
@SerialNumbersCount int,
@UploadedBy varchar(50),
@UploadedDate datetime,
@OutputID int out
as
Begin

BEGIN TRY

declare @BatchQty int,@BatchCount int

begin Transaction SerialNumbers

IF @SerialNumbersCount<>(select top 1 OrderQty from OrderMaster where OrderID=@OrderID and IsDeleted=0)
Begin
set @OutputID=-2
End

Else

Begin

update dbo.PartnerSerialNumbers set
BatchNo = T.N.value('(BatchNo/text())[1]', 'varchar(50)'),DataUploadfromPartner=1,
ExpiryDate = T.N.value('(ExpiryDate/text())[1]', 'Datetime'),SerialNoStatus='O',UploadedBy=@UploadedBy, UploadedDate=@UploadedDate
from @SerialNumberDetails.nodes('Root/SerialNumberDetails') as T(N)
where OrderID = @OrderID and SerialNo=T.N.value('(SerialNumber/text())[1]', 'varchar(50)')

set @BatchCount=@@RowCount
if @BatchCount <> (select top 1 OrderQty from OrderMaster where OrderID=@OrderID and IsDeleted=0)
Begin
set @OutputID=-1
--Rollback Transaction SerialNumbers
End
else
Begin
set @OutputID=1
update OrderMaster set DataUploadfromPartner=1 where OrderID=@OrderID
insert into SerialnumbersLogDetails(OrderID,SerialNo,GTINCode,OrderSentDate,OrderorPartner,
BatchNo,ExpiryDate)
select OrderID,SerialNo,GTINCode,null,'Partner',BatchNo,ExpiryDate
from PartnerSerialNumbers where OrderID=@OrderID
End

End

Commit Transaction SerialNumbers
END TRY
BEGIN CATCH
set @OutputID=0
Rollback Transaction SerialNumbers
END CATCH

End

展开
收起
SONGYiiiD 2019-12-06 21:34:10 1632 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载