解决方案: |
用以下语句删除错误记录:
--4月份
select cwhcode,cinvcode,sum(case when brdflag=1 then iquantity else -iquantity end) as quantity
into sss
from rdrecords a inner join rdrecord b on a.id=b.id
where ddate<‘2003-4-1‘ group by cwhcode,cinvcode
delete st_totalaccount
from st_totalaccount
inner join sss on st_totalaccount.cwhcode=sss.cwhcode and st_totalaccount.cinvcode=sss.cinvcode
and st_totalaccount.ibeginquantity <> sss.quantity
where st_totalaccount.imonth=4
drop table sss
--5月份
select cwhcode,cinvcode,sum(case when brdflag=1 then iquantity else -iquantity end) as quantity
into sss
from rdrecords a inner join rdrecord b on a.id=b.id
where ddate<‘2003-5-1‘ group by cwhcode,cinvcode
delete st_totalaccount
from st_totalaccount
inner join sss on st_totalaccount.cwhcode=sss.cwhcode and st_totalaccount.cinvcode=sss.cinvcode
and st_totalaccount.ibeginquantity <> sss.quantity where st_totalaccount.imonth=5
drop table sss
--6月份
select cwhcode,cinvcode,sum(case when brdflag=1 then iquantity else -iquantity end) as quantity
into sss
from rdrecords a inner join rdrecord b on a.id=b.id
where ddate<‘2003-6-1‘ group by cwhcode,cinvcode
delete st_totalaccount
from st_totalaccount inner join sss on st_totalaccount.cwhcode=sss.cwhcode
and st_totalaccount.cinvcode=sss.cinvcode and st_totalaccount.ibeginquantity <> sss.quantity
where st_totalaccount.imonth=6
drop table sss
--7月份
select cwhcode,cinvcode,sum(case when brdflag=1 then iquantity else -iquantity end) as quantity
into sss
from rdrecords a inner join rdrecord b on a.id=b.id
where ddate<‘2003-7-1‘ group by cwhcode,cinvcode
delete st_totalaccount
from st_totalaccount inner join sss on st_totalaccount.cwhcode=sss.cwhcode
and st_totalaccount.cinvcode=sss.cinvcode and st_totalaccount.ibeginquantity <> sss.quantity
where st_totalaccount.imonth=7
drop table sss |