TB1库存表 
单号       体积
D110827004668 50 TB2出库表
单号       体积
D110827004668 10
结果
1.
生成一张出库记录表
单号               体积
D110827004668C11 10 出库记录表的单号=用原单号+C+当前系统秒
2.
更新库存表
单号        体积
D110827004668 40

解决方案 »

  1.   


    declare @TB2 table (单号 varchar(13),体积 int)
    insert into @TB2
    select 'D110827004668',10select 单号=单号
    +'C'+right(convert(varchar(10),getdate(),108),2),体积 from @TB2
    /*
    单号                 体积
    ------------------ -----------
    D110827004668C44   10
    */
      

  2.   

    update a set 体积=体积-(select sum(体积) from TB2 where 单号=a.单号)
    from TB1 a
      

  3.   

    2update tb1 set 体积=tb1.体积-tb2.体积 from tb1 join tb2 on tb1.单号=tb2.单号
      

  4.   


    declare @TB1 table (单号 varchar(13),体积 int)
    insert into @TB1
    select 'D110827004668',50declare @TB2 table (单号 varchar(13),体积 int)
    insert into @TB2
    select 'D110827004668',10update @TB1 set 体积=a.体积-b.体积
    from @TB1 a left join @TB2 b on a.单号=b.单号select * from @TB1
    /*
    单号            体积
    ------------- -----------
    D110827004668 40
    */
      

  5.   

    生成一张出库记录表 这个按需求应该是先建好这个log表,然后insert ... select ... from ...
    而不是生成一张表