如何在SQL Server 2005中不使用循环或游标更新此查询

时间:2016-06-27 07:34:07

标签: sql-server

ptrace(PTRACE_TRACEME)

那是我的疑问。我想在没有update a_program set total_paguindikatif_rkpd = (select sum(isnull(pagu_dana_rkpd, 0)) from a_kegiatan where id_prog = @id_prog and is_deleted = 0 and id_jenisanggaran = 2 and status in(1,3,7,9) ), total_paguindikatif_kuappas = (select sum(isnull(pagu_dana_kuappas, 0)) from a_kegiatan where id_prog = @id_prog and is_deleted = 0 and id_jenisanggaran = 2 and status in(1,2,3,4,7,8,9,10) ) where id_prog = @id_prog and id_jenisanggaran = 2; @id_prog的情况下自动更新到该查询。我怎么能这样做?

感谢您帮助我...... :)

1 个答案:

答案 0 :(得分:2)

update a set
    total_paguindikatif_rkpd = (select sum(isnull(pagu_dana_rkpd, 0))
                                from a_kegiatan
                                where id_prog = a.id_prog ---<<<
                                  and is_deleted = 0 
                                  and id_jenisanggaran = 2 
                                  and status in(1,3,7,9)
                                ), 
    total_paguindikatif_kuappas = (select sum(isnull(pagu_dana_kuappas, 0))
                                   from a_kegiatan
                                   where id_prog = a.id_prog ---<<<
                                     and is_deleted = 0 
                                     and id_jenisanggaran = 2 
                                     and status in(1,2,3,4,7,8,9,10)
                                    )
from a_program a
where a.id_jenisanggaran = 2;