在交易中,我想打印一条错误消息。我的问题是,即使没有错误,我仍然会在屏幕上打印一个。我如何解决它?交易,其中包含打印语句:
begin tran update_products_and_machine
IF EXISTS (
select*
from TblMachine
where tblMachine.machineNumber = @machineNum and tblMachine.isworking='true')
and EXISTS (
select TblProduct.productNumber
from TblProduct
where TblProduct.productNumber = @ProductNum)
and not exists (select TblProduces.machineNumber, TblProduces.productNumber from TblProduces where TblProduces.productNumber=@productNum
and TblProduces.machineNumber=@machineNum)
begin
insert into TblProduces(productNumber, machineNumber) values (@productNum,@machineNum)
end
if @@ERROR <>0 begin
rollback tran
end
commit tran update_products_and_machine
on_error: Print 'ERROR';