问题描述


科目余额表过滤本期,科目选择'应收账款',显示核算项目,报表显示
有部分客户显示两行数据,正确数据为这两行数据之和
 

问题原因


这种情况一般是由于核算项目横表中被凭证表、余额表引用的核算项目组
合有重复记录导致
 

解决方法

备份账套后请参考如下方法处理:
Use AIS2009###### --(指问题账套的账×××)
(1)创建临时表t_itemdetail_error,把重复核算项目记录插入该表
select a.*, a.fdetailid Fdetailid_temp
into t_itemdetail_error
from t_itemdetail a join t_itemdetail b on a.f1=b.f1 and
a.fdetailcount=b.fdetailcount
where a.fdetailcount=1 and a.fdetailid<>b.fdetailid
and a.f1>0
order by a.f1
(2)在临时表t_itemdetail_error中修改错误的fdetailid值(以最小的fdetailid值为基准):
update b set b.fdetailid_temp=a.fdetailid
from t_itemdetail_error a join t_itemdetail_error b on a.f1=b.f1 and
a.fdetailcount=b.fdetailcount
where a.fdetailcount=1 and a.fdetailidand a.f1>0
(3)创建余额表临时表t_balance_temp :
select * into t_balance_temp from t_balance
order by fyear,fperiod,faccountid,fdetailid,fcurrencyid
(4)更新余额表临时表的错误detailid值:
update a set a.fdetailid=b.fdetailid_temp
from t_balance_temp a join t_itemdetail_error b on a.fdetailid=b.fdetailid
(5)创建临时表temp002:
select top 0 * into temp002 from t_balance
(6)合并t_balance_temp 相同核算项目项的金额,把结果插入temp002:
insert into temp002
(fyear,fperiod,faccountid,fdetailid,fcurrencyid,FFrameWorkID,
FBeginBalanceFor,FDebitFor,FCreditFor,FYtdDebitFor,FYtdCreditFor,FEndBalanceFor,
FBeginBalance,FDebit,FCredit,FYtdDebit,FYtdCredit,FEndBalance,FIsAdjustPeriod)
select fyear,fperiod,faccountid,fdetailid,fcurrencyid,FFrameWorkID,
sum(FBeginBalanceFor)FBeginBalanceFor,sum(FDebitFor)FDebitFor,sum(FCreditFor)FCreditFor,
sum(FYtdDebitFor)FYtdDebitFor,sum(FYtdCreditFor)FYtdCreditFor,sum(FEndBalanceFor)FEndBalanceFor,
sum(FBeginBalance)FBeginBalance,sum(FDebit)FDebit,sum(FCredit)FCredit,sum(FYtdDebit)FYtdDebit,
sum(FYtdCredit)FYtdCredit,sum(FEndBalance)FEndBalance,sum(FIsAdjustPeriod)FIsAdjustPeriod
from t_balance_temp
group by fyear,fperiod,faccountid,fdetailid,fcurrencyid,FFrameWorkID
(7)清空t_balance数据 :
delete from t_balance
(8)把temp002的值写回t_balance:
insert into t_balance
(fyear,fperiod,faccountid,fdetailid,fcurrencyid,FBeginBalanceFor,FDebitFor,FCreditFor,FYtdDebitFor,
FYtdCreditFor,FEndBalanceFor,FBeginBalance,FDebit,FCredit,FYtdDebit,FYtdCredit,FEndBalance,FFrameWorkID,FIsAdjustPeriod)
select
fyear,fperiod,faccountid,fdetailid,fcurrencyid,FBeginBalanceFor,FDebitFor,FCreditFor,FYtdDebitFor,
FYtdCreditFor,FEndBalanceFor,FBeginBalance,FDebit,FCredit,FYtdDebit,FYtdCredit,FEndBalance,FFrameWorkID,FIsAdjustPeriod
from temp002
(9)删除t_itemdetail中的重复值:
delete from t_itemdetail
where fdetailid in (select fdetailid from t_itemdetail_error)
and fdetailid not in (select fdetailid_temp from t_itemdetail_error)
(10)更新纵表:
exec sp_cleanitemdetailv
(11)更正凭证分录数据:
update a set a.fdetailid=b.fdetailid_temp
from t_voucherentry a join t_itemdetail_error b on a.fdetailid=b.fdetailid
where a.fdetailid<>b.fdetailid_temp