update b set b.总数量=a.tmpsum
from b,(select 单号,sum(数量) as tmpsum from a group by 单号) as a
where b.单号=a.单号

解决方案 »

  1.   

    select 单号,isnull(sum(数量),0) 数量 FROM A
    Group by 单号
      

  2.   

    if exists( select 单号 from a where 单号 in (select 单号 from b ))
       update b set b.总数量=a.tmpsum
       from b,(select 单号,sum(数量) as tmpsum from a group by 单号) as a
       where b.单号=a.单号
    else
       insert b
       select b.单号,b.总数量
       from b,(select 单号,sum(数量) as tmpsum from a group by 单号) as a
       where b.单号=a.单号