解决方案: |
--检查发现在ap_detail表中相应记录的部门编码为空,将其对应原始记录后回写即可。执行如下语句:
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) |