解决方案: |
经过检查,发现在该存货中本批次进入了84个,但在rdrecords表内isoutquantity(累计出库数量)内有发出数量两个,但没有该出库单号关联的出库单,分析为客户可能作过出库两个但后来将该出库单删除但不知何原因未在系统内将isoutquantity(累计出库数量)发出数量两个同步删除造成此现象,请按步骤执行下面语句调整即可: 1、select cvouchcode into ee from rdrecords where cvouchcode is not null 2、select * from rdrecords where autoid in (select rdid from mainbatch) and autoid not in (select cvouchcode from ee) and isnull(isoutquantity,0)<>0 3、update rdrecords set isoutquantity=0 where autoid in (select rdid from mainbatch) and autoid not in (select cvouchcode from ee) and isnull(isoutquantity,0)<>0 4、drop table ee 5、select cvouchcode,sum(abs(iquantity)) as sum into cc from rdrecord a join rdrecords b on a.id=b.id group by cvouchcode 6、select b.iquantity,isoutquantity,* from cc a join rdrecords b on a.cvouchcode=b.autoid where a.sum<>isoutquantity and a.sum>abs(iquantity) 7、select b.iquantity,isoutquantity,* from cc a join rdrecords b on a.cvouchcode=b.autoid where a.sum<>isoutquantity and a.sum<=abs(iquantity) 8、update rdrecords set isoutquantity=a.sum from cc a join rdrecords b on a.cvouchcode=b.autoid where a.sum<>isoutquantity and a.sum<=abs(iquantity) 9、delete from mainbatch where rdid not in (select autoid from rdrecords) 10、update mainbatch set bisnull=1 from mainbatch a join rdrecords b on a.rdid=b.autoid where b.iquantity=isoutquantity and bisnull=0 |