set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTERProcedure[dbo].[prInsertLeasedAsset_6] -- Insert leased asset and update total in LeaseSchedule. ( @intEquipmentIdint, @intLocationIdint, @intStatusIdint, @intLeaseIdint, @intLeaseScheduleIdint, @intOwnerIdint, @mnyLeasemoney, @intAcquisitionTypeIDint, @intInventoryIdint OUTPUT ) As set nocount on SET XACT_ABORT ON--当SQL SERVER在出现错误时候回滚整个事务 Declare@intErrorCodeint, @intTransactionCountOnEntryint Select@intErrorCode=@@Error If@intErrorCode=0and@@trancount=0-- Begin Select@intTransactionCountOnEntry=@@TranCount BEGINTRANSACTION End If@intErrorCode=0 begin -- insert asset insert Inventory(EquipmentId, LocationId, StatusId, LeaseId, LeaseScheduleId, OwnerId, Lease, AcquisitionTypeID) values ( @intEquipmentId, @intLocationId, @intStatusId, @intLeaseId, @intLeaseScheduleId, @intOwnerId, @mnyLease, @intAcquisitionTypeID) Select@intErrorCode=@@Error, @intInventoryId=@@identity end If@intErrorCode=0 begin -- update total update LeaseSchedule Set PeriodicTotalAmount = PeriodicTotalAmount +@mnyLease where LeaseId =@intLeaseId Select@intErrorCode=@@Error end If@@TranCount>@intTransactionCountOnEntry Begin If@intErrorCode=0 COMMITTRANSACTION Else ROLLBACKTRANSACTION End return@intErrorCode