解决方案: |
解决方法: 请执行如下脚本,将AP_detail 表中 cdeptcode 为 NULL的字段,按照发生相应单据的部门编码进行回写,执行前请做好数据备份: select max(cCancelNo) as ccancelno into bb From Ap_DetailCust_V where cFlag='AR' and iflag<>0 or sum(icamount) <> 0 Or sum(idamount_f)<>0 or sum(icamount_f) <> 0 ) and cdeptcode is null select max(cdeptcode)as cdeptcode, max(bb.ccancelno)as ccancelno into cc from ap_detail,bb where ap_detail.ccancelno=bb.ccancelno group by bb.ccancelno update ap_detail set cdeptcode=salebillvouch.cdepcode from salebillvouch join ap_detail on salebillvouch.csbvcode=ap_detail.cvouchid and salebillvouch.cvouchtype=ap_detail.cvouchtype where ccancelno in(select ccancelno from cc where cdeptcode is null) update ap_detail set cdeptcode=ap_closebill.cdeptcode from ap_closebill join ap_detail on ap_closebill.cvouchid=ap_detail.cvouchid and ap_closebill.cvouchtype=ap_detail.cvouchtype where ap_detail.ccancelno in(select ccancelno from cc where cdeptcode is null) update ap_detail set cdeptcode=aa.cdeptcode from ap_detail join (select cdeptcode,ccancelno from cc where cdeptcode is not null) aa on ap_detail.ccancelno=aa.ccancelno where ap_detail.cdeptcode is null drop table bb drop table cc |