p_NLOO_CheckRDCInv USE [AIS20070827152351] GO /****** 对象: StoredProcedure [dbo].[p_NLOO_CheckRDCInv] 脚本日期: 06/28/2011 08:49:19 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* K/3即时库存-占用库存+该订单当前保存记录的数量>=传入数量时可发货 exec sp2_CheckRDCInv 1949,1724,363,0 exec sp2_CheckRDCInv 10465,1725,10,0 exec sp2_CheckRDCInv 10465,1724,10,0 */ ALTER procedure [dbo].[p_NLOO_CheckRDCInv] @StockID int, @ItemID int, @Qty decimal(23,2), @BillID int, @UseCanRDCNagOut int = 1 --是否允许考虑缺货可订货 AS set nocount on declare @RltFlag int declare @RltMsg varchar(1000) declare @CanRDCNagOut int declare @K3Inv decimal(23,10) declare @LockQty decimal(23,10) declare @OrderSaveQty decimal(23,10) declare @ActInv decimal(23,10) --是否缺货可发货 set @CanRDCNagOut = case when @UseCanRDCNagOut = 1 and exists( -- 按日期排序取每个RDC最后一张已审核的可订货名录,从中寻找是否存在对应商品。 select 1 from tb_RDCOrderNoInvEntry where fItemID = @ItemID and fid in (select top 1 fID from tb_RDCOrderNoInv where isnull(fCheckerID,0) > 0 and fRDCID = @StockID order by fDate desc, fID desc) ) then 1 else 0 end if @CanRDCNagOut = 1 begin select @RltFlag = 1, @RltMsg = '缺货可订货' end else begin --K3即时库存 select @K3Inv = isnull(sum(fQty), 0) from icinventory where fStockID = @StockID and fItemID = @ItemID --占用库存 select @LockQty = isnull(sum(FLockQty), 0) from tb_InvLock where FRDCID = @StockID and FItemID = @ItemID set @ActInv = isnull(@K3Inv, 0) - isnull(@LockQty, 0) if @Qty <= @ActInv begin select @RltFlag = 1, @RltMsg = '库存满足订货需求' end else begin begin select @RltFlag = -1, @RltMsg = '即时可用库存为[' + dbo.fn_Dec2Var(@ActInv) + '],超出[' + dbo.fn_Dec2Var(@Qty - @ActInv) + ']!' end end end H_End: select isnull(@RltFlag, -100) Flag, isnull(@RltMsg, '未预期的返回值!') RltMsg by Wangy