现在做一个仓库管理系统,比如过我有2个入库单:A,B,2个入库单的产品都为:c。然后我出库的时候,怎么能保证,我出的产品C,是先出完A单上面的产品再出B的产品呢。咱分不多,请教各位了。比方说 A单10个C产品,B单10个C产品,然后我要出15个C产品,怎么才能把A出完,再拿B单上面的5个C产品。

解决方案 »

  1.   

    呵呵 咱不大会,能稍微说详细点吗,先baidu fifo 呵呵
      

  2.   

    根据入库的时间顺序来update,看下面的例子
    --利用不停变化的@i,更新表值
    create table t1(编号 int,姓名 varchar(4),金额 int)
    insert into t1
    select 1,'张三',17 union all
    select 2,'李四',210 union all
    select 3,'张三',2 union all
    select 4,'李四',12 union all
    select 5,'张三',12--张三 消费 22
    declare @i int;set @i=22update t1
    set @i=case when @i<0 then 0 else @i-金额 end,
    金额=case when @i>0 then 0 when @i=0 then 金额 else -@i end
    where 姓名='张三'select * from t1
    /*
    编号          姓名   金额
    ----------- ---- -----------
    1           张三   0
    2           李四   210
    3           张三   0
    4           李四   12
    5           张三   9
    */
    @i=5     金额=0   
    @i=3     金额=0   
    @i=-9    金额=9