解决方案: |
经过检查发现升级到852后部分库存期初数据出现调整错误(系统自动调整记录有‘850补丁调整工具调整数据’标志的),根据821st_totalaccount表回写852rd表中部分期初不正确的记录,以下为执行语句,请先作好数据备份!
select cwhcode,cinvcode,sum(ibeginquantity)as sl
into bb
from st_totalaccount where imonth='1' group by cwhcode,cinvcode
select cwhcode,cinvcode, sum(case when brdflag=1 then iquantity else -1*iquantity end) as xsl
into yy1
from rdrecord join rdrecords on rdrecord.id=rdrecords.id where bisstqc=1 group by cwhcode,cinvcode
select bb.cwhcode,bb.cinvcode,bb.sl,isnull(yy1.xsl,0)as xsl
into tt
from bb left join yy1 on bb.cwhcode=yy1.cwhcode and bb.cinvcode=yy1.cinvcode
select cwhcode,cinvcode,sl-xsl as cha
into zn
from tt where ((sl<>0 and xsl<>0) or (sl<>0 and xsl=0) or (sl=0 and xsl<>0)) and sl<>xsl
select max(autoid)as autoid,cwhcode,cinvcode
into rdsid
from rdrecord join rdrecords on rdrecord.id=rdrecords.id
where bisstqc=1 and cmemo='850补丁调整工具调整数据' group by cwhcode,cinvcode
select zn.cwhcode,zn.cinvcode,zn.cha,rdsid.autoid
into gx
from zn join rdsid on zn.cwhcode=rdsid.cwhcode and zn.cinvcode=rdsid.cinvcode
update rdrecords
set iquantity=iquantity+gx.cha
from gx join rdrecords on gx.autoid=rdrecords.autoid
select * from zn left join rdsid on zn.cwhcode=rdsid.cwhcode and zn.cinvcode=rdsid.cinvcode where autoid is null
drop table bb
drop table yy1
drop table tt
|