解决方案: |
SELECT sum(idamount) as idamount,sum(idamount_f) as idamount_f,
sum(icamount_f) as icamount_f,sum(icamount) as icamount,ibvid
INTO a
FROM Ap_Detail
WHERE (cFlag = ‘ar‘) AND (cCoVouchType IN 9‘26‘, ‘27‘,‘28‘,‘29‘))
and (iFlag <> ‘5‘ or cprocstyle<>‘xj‘)
group by ibvid --包括了核销、预收冲应收、应收冲应付操作。
update salebillvouchs
set imoneysum=a.icamount,iexchsum=a.icamount_f
from salebillvouchs b
inner join a on a.ibvid = b.autoid and a.idamount=b.inatsum and a.idamount_f=b.isum
SELECT sum(idamount) as idamount,sum(idamount_f) as idamount_f,
sum(icamount_f) as icamount_f,sum(icamount) as icamount,ibvid
INTO a
FROM Ap_Detail
WHERE (cFlag = ‘ar‘) AND (cCoVouchType IN 9‘26‘, ‘27‘,‘28‘,‘29‘))
and (iFlag <> ‘5‘ or cprocstyle<>‘xj‘)
group by ibvid --包括了核销、预收冲应收、应收冲应付操作。
update salebillvouchs
set imoneysum=a.icamount,iexchsum=a.icamount_f
from salebillvouchs b
inner join a on a.ibvid = b.autoid and a.idamount=b.inatsum and a.idamount_f=b.isum
因为SALEBILLVOUCHS表中的有些记录与AP_DETAIL 中的对应记录的金额不一致,不知什么原因(因为无上年的数据),用AP_DETAIL中的价税合计更新SALEBILLVOUCHS表中的价税合计及累计收款额。
而如果不取消核销的话,以前的核销的数据会有错误,建议把相关客户的核销取消,如已制单,把凭证删去,或把凭证冲销,再做以下更新。
SELECT sum(idamount) as idamount,sum(idamount_f) as idamount_f,
sum(icamount_f) as icamount_f,sum(icamount) as icamount,ibvid
INTO a
FROM Ap_Detail
WHERE (cFlag = ‘ar‘) AND (cCoVouchType IN (‘26‘, ‘27‘,‘28‘,‘29‘))
and (iFlag <> ‘5‘ or cprocstyle<>‘xj‘)
group by ibvid
--包括了核销、预收冲应收、应收冲应付操作。
update salebillvouchs
set imoneysum=a.icamount,iexchsum=a.icamount_f
from salebillvouchs b inner join a on a.ibvid = b.autoid
--因为有的红字发票的金额为零的记录在AP_DETAIL中的IDAMOUNT不为零,如CY00021081号发票,只能用更新ISUM,INATSUM的方法了。但不知数据是否在上一年度有错,现在只能按AP_DETAIL为正确的进行调整了。
update salebillvouchs
set imoneysum=a.icamount,iexchsum=a.icamount_f, inatsum=a.idamount,b.isum=a.idamount_f
from salebillvouchs b inner join a on a.ibvid = b.autoid
|