朋友,你使用的金蝶K3系列产品吗?金蝶K3在总账初始数据录入中,有时会出现综合本位币的金额不随着原币金额变动的情况(尤其是设置了核算项目的科目)
--问题可能是程序中对期初余额中纪录的修改和删除操作,只更新了原币的纪录,没有更新对应的本位币纪录,造成本位币与原币不符。
可以在查询分析器中,选定该账套对应的数据库后,执行下述语句:
--将所有本位币记录中与原币不等的记录更新
update a
set
fbeginbalancefor = b.fbeginbalancefor,
fdebitfor = b.fdebitfor,
fcreditfor = b.fcreditfor,
fytddebitfor = b.fytddebitfor,
fytdcreditfor = b.fytdcreditfor,
fendbalancefor = b.fendbalancefor,
fbeginbalance = b.fbeginbalance,
fdebit = b.fdebit,
fcredit = b.fcredit,
fytddebit = b.fytddebit,
fytdcredit = b.fytdcredit,
fendbalance = b.fendbalance
from
t_balance b, t_balance a
where
a.fyear = b.fyear
and a.fperiod = b.fperiod
and a.faccountid = b.faccountid
and a.fdetailid = b.fdetailid
and a.fcurrencyid = '0'
and b.fcurrencyid = '1'
and
(a.fbeginbalancefor <> b.fbeginbalancefor
or a.fdebitfor <> b.fdebitfor
or a.fcreditfor <> b.fcreditfor
or a.fytddebitfor <> b.fytddebitfor
or a.fytdcreditfor <> b.fytdcreditfor
or a.fendbalancefor <> b.fendbalancefor
or a.fbeginbalance <> b.fbeginbalance
or a.fdebit <> b.fdebit
or a.fcredit <> b.fcredit
or a.fytddebit <> b.fytddebit
or a.fytdcredit <> b.fytdcredit
or a.fendbalance <> b.fendbalance)
--以原币记录为基础,直接将所有查询到的本位币缺少的分录插入到余额表中
insert into t_balance
select
fyear,fperiod,faccountid,fdetailid,
(case when fcurrencyid = '1' then '0' else '1' end) as fcurrencyid,
fbeginbalancefor,fdebitfor,fcreditfor,fytddebitfor,fytdcreditfor,
fendbalancefor,fbeginbalance,fdebit,fcredit,fytddebit,fytdcredit,
fendbalance,fframeworkid
from
t_balance
where
faccountid + '_' + fdetailid + '_' + fperiod in
(select
faccountid + '_' + fdetailid + '_' + fperiod
from
(select * from t_balance where fcurrencyid = 1) as a
where
faccountid+ '_' +fdetailid+ '_' +fperiod not in
(select faccountid+ '_' +fdetailid+ '_' +fperiod from t_balance where fcurrencyid = 0))
--删除综合本位币中多出的记录
delete from t_balance
where
fcurrencyid = 0
and faccountid + '_' + fdetailid + '_' + fperiod not in
(select faccountid+ '_' +fdetailid+ '_' +fperiod from t_balance where fcurrencyid = 0)