存储过程:产品自动入库

这是一个关于SQL存储过程的示例,用于自动化产品入库。该过程首先检查生产任务单的状态和剩余入库数量,然后根据条件插入产品入库单据头表和明细表,并更新相关库存和领用数量。
摘要由CSDN通过智能技术生成


alter PROCEDURE cpinstock
(@FBillNO varchar(255),@FName varchar(255),@FQty decimal(28, 10),@FEntryID int, @insert int out)

as
begin
---判断条件:生产任务单必须是下达状态,未完全入库
    if exists(
        select 1 from icmo a
        inner join t_icitem b on a.FItemID = b.FitemID
        where substring(FBillNo,0,charindex('*',FBillNo)) = @FBillNO
        and b.FName = @FName
        and a.FSourceEntryID = @FEntryID
        and (FQty-FCommitQty) < @FQty    
        )
        begin
            --返回错误提示 
--            RAISERROR('错误:已入库!',16,1) 
        --不允许插入,更新变量为0,返回变量
        set @insert = 0
        end
    else
        begin
            declare @FInterID_1 int 
            exec GetICMaxNum 'icstockbill',@FInterID_1 output,1
--            select @FInterID_1
            declare @FMaxCINint int  
            select @FMaxCINint = cast(substring(FBillNo,4,6) as int) from icstockbill
            where FTranType = 2
            and FinterID in (select Max(FinterID) from icstockbill where FTranType = 2)

    ----插入产品入库单据头表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值