--查询
select c_ptid,F_STOCKSYS=isnull((
select sum(F_STOCKSYS) from bs_rep_day_lh
where D_date = '2004-8-1'
and c_ptid like a.c_ptid+'%'),0)
from bs_rep_day_lh a
where d_date = '2004-8-1'

解决方案 »

  1.   

    --直接更新
    update a set F_STOCKSYS=isnull((
    select sum(F_STOCKSYS) from bs_rep_day_lh
    where D_date = '2004-8-1'
    and c_ptid like a.c_ptid+'%'),0)
    from bs_rep_day_lh a
    where d_date = '2004-8-1'
      

  2.   

    --用join实现查询
    select a.c_ptid,F_STOCKSYS=sum(b.F_STOCKSYS)
    from bs_rep_day_lh a
    left join bs_rep_day_lh b 
    on a.D_date = '2004-8-1'
    and b.D_date = '2004-8-1'
    and b.c_ptid like a.c_ptid+'%'
    group by a.c_ptid
    order by a.c_ptid