解决方案: |
if exists (select * from sysobjects where name='aa') drop table aa if exists (select * from sysobjects where name='bb') drop table bb if exists (select * from sysobjects where name='cc') drop table cc if exists (select * from sysobjects where name='ff') drop table ff if exists (select * from sysobjects where name='uu') drop table uu if exists (select * from sysobjects where name='yy') drop table yy select cpzid into aa from ap_detail where cvouchtype='48' and cflag='ar' and (icamount<>0 or icamount_f<>0) and iflag=0 and cprocstyle='48' and bprepay=0 and cpzid is not null and ccode is null group by cpzid select aa.cpzid, ccode into ff from ap_detail join aa on ap_detail.cpzid=aa.cpzid group by aa.cpzid,ap_detail.ccode having ap_detail.ccode is not null select icoclosesid into bb from ap_detail where cvouchtype='48' and cflag='ar' and (icamount<>0 or icamount_f<>0) and iflag=0 and cprocstyle='48' and bprepay=0 and cpzid is null and ccode is null select id,ckm into cc from ap_closebills join bb on ap_closebills.id=bb.icoclosesid select iclosesid into uu from ap_detail where cvouchtype='48' and cflag='ar' and (icamount<>0 or icamount_f<>0) and iflag=0 and cprocstyle='9p' and ccode is null select ckm,id into yy from ap_closebills join uu on ap_closebills.id=uu.iclosesid update ap_detail set ccode=cc.ckm from ap_detail join cc on ap_detail.icoclosesid=cc.id where ccode is null update ap_detail set ap_detail.ccode=ff.ccode from ap_detail join ff on ap_detail.cpzid=ff.cpzid where cvouchtype='48' and cflag='ar' and (icamount<>0 or icamount_f<>0) and iflag=0 and cprocstyle='48' and bprepay=0 and ap_detail.cpzid is not null and ap_detail.ccode is null update ap_detail set ap_detail.ccode=ff.ccode from ap_detail join ff on ap_detail.cpzid=ff.cpzid where cprocstyle='9P' and ccovouchtype='48' and cflag='ar' and ap_detail.cpzid is not null and ap_detail.ccode is null update ap_detail set ccode=yy.ckm from ap_detail join yy on ap_detail.iclosesid=yy.id where cvouchtype='48' and cflag='ar' and (icamount<>0 or icamount_f<>0) and iflag=0 and cprocstyle='9p' and ccode is null |