错误出现在我取消后回滚事务行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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。