在存储过程中,我想实现循环统计,不晓得如何实现,麻烦好心人了:
select kc_bm from kw_tk_bk where xs_zxm=@xs_zxm and xs_sfz=@xs_sfz and zy_bm=@zy_bm
取出kc_bm比如为:01256 01245 01378
然后根据这个kc_bm搜索
Select kc_Money From jh_fa_kc_fy where kc_bm=@kc_bm
最后把这三个kc_bm对应的kc_money加起来返回给程序,如何实现?
select kc_bm from kw_tk_bk where xs_zxm=@xs_zxm and xs_sfz=@xs_sfz and zy_bm=@zy_bm
取出kc_bm比如为:01256 01245 01378
然后根据这个kc_bm搜索
Select kc_Money From jh_fa_kc_fy where kc_bm=@kc_bm
最后把这三个kc_bm对应的kc_money加起来返回给程序,如何实现?
where m.kc_bm = n.kc_bm and n.xs_zxm=@xs_zxm and n.xs_sfz=@xs_sfz and n.zy_bm=@zy_bm
select sum(kc_Money) from
(
Select m.kc_Money From jh_fa_kc_fy m,kw_tk_bk n
where m.kc_bm = n.kc_bm and n.xs_zxm=@xs_zxm and n.xs_sfz=@xs_sfz and n.zy_bm=@zy_bm
union all
Select kc_Money = 26 From jh_fa_kc_fy m where kc_bm not in (select kc_bm from kw_tk_bk n
where n.xs_zxm=@xs_zxm and n.xs_sfz=@xs_sfz and n.zy_bm=@zy_bm)
) t
where n.xs_zxm=@xs_zxm and n.xs_sfz=@xs_sfz and n.zy_bm=@zy_bm 这个选择出来的太多了。
(
Select m.fy From jh_fa_kc_fy m,kw_tk_bk n
where m.kc_bm = n.kc_bm and n.xs_sfz=@xs_sfz and n.zy_bm=@zy_bm
union all
Select fy = 26 From kw_tk_bk n where n.zy_bm=@zy_bm and n.xs_sfz=@xs_sfz
and n.kc_bm not in (select kc_bm from jh_fa_kc_fy)
) t
这样就对了,谢谢你!!