set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER Procedure [dbo].[prInsertLeasedAsset_6]
-- Insert leased asset and update total in LeaseSchedule.
(
@intEquipmentId int,
@intLocationId int,
@intStatusId int,
@intLeaseId int,
@intLeaseScheduleId int,
@intOwnerId int,
@mnyLease money,
@intAcquisitionTypeID int,
@intInventoryId int OUTPUT
)
As
set nocount on
SET XACT_ABORT ON--当SQL SERVER在出现错误时候回滚整个事务
Declare @intErrorCode int,
@intTransactionCountOnEntry int
Select @intErrorCode = @@Error
If @intErrorCode = 0 and @@trancount = 0--
Begin
Select @intTransactionCountOnEntry = @@TranCount
BEGIN TRANSACTION
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
COMMIT TRANSACTION
Else
ROLLBACK TRANSACTION
End
return @intErrorCode
本文介绍了一个SQL存储过程,用于插入租赁资产记录并更新租赁计划的周期总金额。该过程接收多个输入参数,包括设备ID、位置ID、状态ID等,并输出库存ID。
3281

被折叠的 条评论
为什么被折叠?



