您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



求助,一个先进先出的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求助,一个先进先出的问题[已结贴,结贴人:yofee]
发表于:2008-01-16 10:50:55 楼主
求助
问题描述:      
                        同一个产品在成品时分多次入库。出库时希望能按先进先出原则来实现(自动减分批入库数据)。      
       
    入库表的表结构:      
               
                名称               代号                     工号                     批次                   入库数量             库存数据             入库时间      
                a1                   ab                           ac                           p06                       30                       30                     2006-5-12      
                a1                   ab                           ac                           p06                       50                       50                     2006-5-13      
                a1                   abc                         ac                           p06                       230                   230                     2006-5-13      
       
    目的:      
        在出库时候,出a1、ab、ac       数量40       对应出库单号为   a


    入库结果是:      
                名称               代号                     工号                       批次                     入库数量         库存数据                 入库时间      
                a1                   ab                           ac                           p06                       30                     0                             2006-5-12      
                a1                   ab                           ac                           p06                       50                     40                           2006-5-13      
                a1                   abc                         ac                           p06                       230                   230                         2006-5-13      

    将这个变化记入另外一个表  
                名称                       代号                     工号                       批次                     出库单号           数量                   入库时间      
                a1                           ab                           ac                           p06                       a                       30                     2006-5-12      
                a1                           ab                           ac                           p06                       a                       10                     2006-5-13      


前面有个高人用存储过程编写了出库的动作,代码如下
2   楼louisxiv(夜游神)回复于   2006-06-22   18:51:03   得分   50
if       exists(select       1       from       sysobjects       where       id=object_id('input')       and       xtype='u')       drop       table       input      
    go      
    create       table       input      
    (      
    名称       varchar(2),      
    代号       varchar(3),      
    工号       varchar(2),      
    批次       varchar(3),      
    入库数量       int,      
    库存数据       int,      
    入库时间       varchar(10)      
    )      
    insert       into       input      
    select       'a1','ab','ac','p06',30,30,'2006-05-12'       union       all      
    select       'a1','ab','ac','p06',50,50,'2006-05-13'       union       all      
    select       'a1','ab','ac','p06',50,50,'2006-05-14'       union       all      
    select       'a1','abc','ac','p06',230,230,'2006-05-13'      
       
    select       *       from       input      
       
    declare       @a       varchar(2),@b       varchar(3),@c       varchar(2),@d       int      
    select       @a='a1',@b='ab',@c='ac',@d=100      
       
       
       
    declare       @char1       varchar(10),@char2       int      
    select       @char1=min(入库时间),@char2=min(库存数据)      
    from      
    (      
    select       入库时间,(select       sum(库存数据)       from       input       where       名称=a.名称       and       代号=a.代号       and       代号=a.代号       and       入库时间 <=a.

入库时间)as       库存数据      
    from       input       a      
    where       名称=@a       and       代号=@b       and       工号=@c      
    )a      
    where       库存数据> @d      
       
       
    update       input      
    set       库存数据=0      
    where       入库时间 <@char1      
    and       名称=@a       and       代号=@b       and       工号=@c      
       
    update       input      
    set       库存数据=@char2-@d      
    where          
    入库时间=@char1       and       名称=@a       and       代号=@b       and       工号=@c      
       
    select       *       from       input      
       
       
    drop       table       input      
       
    /*      
    名称           代号         工号             批次     入库数量                                 库存数据                                   入库时间                                  
    ----           ----       ----             ----       -----------                           -----------                           ----------          
    a1               ab               ac               p06           30                                           30                                           2006-05-12      
    a1               ab               ac               p06           50                                           50                                           2006-05-13      
    a1               ab               ac               p06           50                                           50                                           2006-05-14      
    a1               abc             ac               p06           230                                         230                                       2006-05-13      
       
    名称           代号         工号           批次       入库数量                                   库存数据                                   入库时间                                  
    ----       ----       ----       ----       -----------       -----------       ----------          
    a1               ab               ac               p06           30                                           0                                               2006-05-12      
    a1               ab               ac               p06           50                                           0                                               2006-05-13      
    a1               ab               ac               p06           50                                           30                                             2006-05-14      
    a1               abc             ac               p06           230                                       230                                             2006-05-13      


我没学过存储过程,一时也不知道怎么改动才能得到我想要的,希望哥哥姐姐们帮帮忙,看看如果用存储过程,怎么把后面的这个记入表的动作加上去,或者是

不是不用存储过程也能实现?怎么实现?
发表于:2008-01-16 16:52:331楼 得分:50
你要是在数据库里做就用存储过程
要是在vb里实现只要对入库记录循环就行
发表于:2008-01-17 09:09:562楼 得分:0
楼上的能说得具体一点吗?
我是个小菜鸟,太抽象了就不懂了,可以给个例子看看吗?
发表于:2008-01-17 09:11:303楼 得分:0
我个人倾向于后一种方法,如果两种方法都教教我,最好了,帖子我又追加了100分。先谢谢ling242a  
发表于:2008-01-17 10:32:434楼 得分:145
我用的oracle数据库,那个时间操作需要改成你自己的,你也可以出库数据作为一个参数,直接传进去,像这样
private   function   fifo(stroutno   as   string,strname   as   string,strcode   as   string,dim   strempid   as   string,dblqty   as   double)   as   boolean

end   function
vbscript code
private function fifo() as boolean dim stroutno as string dim strname as string dim strcode as string dim strempid as string dim dblqty as double dim strsql as string dim rstmp as new adodb.recordset dim g_adoconn as new adodb.connection stroutno = "a" strname = "a1" strcode = "ab" strempid = "ac" dblqty = 40 fifo=false on error goto errmsg strsql = "select * from 入库表 where 名称='" & strname _ & "' and 代号='" & strcode & "' and 工号='" & strempid & "' " _ & "order by 入库时间" rstmp.open strsql, g_adoconn, adopenkeyset, adlockreadonly '把g_adoconn改成你的数据库连接 g_adoconn.begintrans do until rstmp.eof if dblqty = 0 then exit do if rstmp("库存数据") >= dblqty then strsql = "update 入库表 set 库存数据=" & rstmp("库存数据") - dblqty _ & " where 名称='" & strname & "' and 代号='" & strcode & "' and 工号='" & strempid _ & "' and 入库时间=to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd')" g_adoconn.EXECute strsql strsql = "insert into 出库记录 (名称,代号,工号,批次,出库单号,数量,入库时间) values('" _ & strname & "','" & strcode & "','" & strempid & "','" & rstmp("批次") & "','" _ & stroutno & "'," & dblqty & ",to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd'))" g_adoconn.EXECute strsql dblqty = 0 else strsql = "update 入库表 set 库存数据=0" _ & " where 名称='" & strname & "' and 代号='" & strcode & "' and 工号='" & strempid _ & "' and 入库时间=to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd')" g_adoconn.EXECute strsql strsql = "insert into 出库记录 (名称,代号,工号,批次,出库单号,数量,入库时间) values('" _ & strname & "','" & strcode & "','" & strempid & "','" & rstmp("批次") & "','" _ & stroutno & "'," & rstmp("库存数据") & ",to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd'))" g_adoconn.EXECute strsql dblqty = dblqty - rstmp("库存数据") end if rstmp.movenext loop if dblqty > 0 then msgbox "没有这么多库存!" g_adoconn.rollbacktrans exit sub end if g_adoconn.committrans fifo=true rstmp.close set rstmp = nothing exit sub errmsg: g_adoconn.rollbacktrans msgbox err.description end function
发表于:2008-01-17 10:33:565楼 得分:0
大概就是这样吧,没有测试过滴,不好意思
发表于:2008-01-17 10:36:396楼 得分:5
up,xuexi
发表于:2008-01-17 11:29:067楼 得分:0
好了,看懂了,ling242a   ,真是谢谢你啊,加分结贴


快速检索

最新资讯
热门点击