解决方案: |
但升级到861后,2006年的库存期初是有错误的。您可通过下面的语句进行调整: update rdrecord set bisstqc=0 where cvouchtype<>'34' and bisstqc=1 update a set bisstqc=0 from rdrecord a inner join rdrecords b on a.id=b.id where bisstqc=1 and (cmemo not like ('850补丁调整工具调整数据') or cmemo is null) select cwhcode,cinvcode,max(a.id) as id into tmp02 from rdrecord a inner join rdrecords b on a.id=b.id where bisstqc=1 and cmemo like ('850补丁调整工具调整数据') group by cwhcode,cinvcode delete from rdrecords where id in (select a.id from rdrecord a inner join rdrecords b on a.id=b.id left join tmp02 c on a.id=c.id where bisstqc=1 and cmemo like ('850补丁调整工具调整数据') and c.id is null) delete from rdrecord where id in (select a.id from rdrecord a left join tmp02 c on a.id=c.id where bisstqc=1 and cmemo like ('850补丁调整工具调整数据') and c.id is null) select a.autoid,a.cwhcode,a.cinvcode,a.iquantity,b.stquantity into tmp03 from (select autoid,cwhcode,cinvcode,iquantity from rdrecord a inner join rdrecords b on a.id=b.id where bisstqc=1 and cmemo like ('850补丁调整工具调整数据')) a inner join (select cwhcode,cinvcode,sum(ibeginquantity) as stquantity from st_totalaccount where imonth=1 group by cwhcode,cinvcode) b on a.cwhcode=b.cwhcode and a.cinvcode=b.cinvcode update a set iquantity=b.stquantity from rdrecords a inner join tmp03 b on a.autoid=b.autoid 调整后,通过下面的语句查询期初合计即可: /*收发记录主子表中的期初数据*/ select sum(case when brdflag=1 then iquantity else -iquantity end) from rdrecord a inner join rdrecords b on a.id=b.id where bisstqc=1 /*库存总账表中的期初数据*/ select sum(ibeginquantity) from st_totalaccount where imonth=1 【注意事项】 执行脚本前请务必做好数据备份!!! |