解决方案: |
1、备份。
2、恢复存货期初记帐。
3、在查询分析中分步执行SQL脚本。
4、重新记帐。 注意(执行该脚本后存货期初和去年一致,计价辅助表,总帐 由存货期初记帐后形成。 另外注意,因为无法再根据单据来调整,所以执行该脚本后所有单据以期初入库单的方式出现,日期全部是2004-12-31, 2005-1-1)
--注意一定要先在存货中取消期初记帐后操作
use ufdata_888_2004
go
--清空2005年的期初
delete from ufdata_888_2005..ia_subsidiary where cvoutype='34'
go
--从04年存货明细帐中取数放到TEMP02中
select cdepcode,cwhcode,cinvcode,(case when brdflag=0 then ioutcost else iincost end) as cost,
(case when brdflag=0 then -sum(iaoutquantity) else sum(iainquantity) end ) as sumqu ,
(case when brdflag=0 then -sum(iaoutprice) else sum(iainprice) end ) as sumpr
into temp02
from ia_subsidiary
where cvoutype<>'33'
group by cdepcode,cwhcode,cinvcode,brdflag,iincost,ioutcost
go
--汇总后放到TEMP02中
select cdepcode,cwhcode,cinvcode,cost,sum(sumqu) as qu,sum(sumpr) as pr
into temp03
from temp02
group by cdepcode,cwhcode,cinvcode,cost
go
--将汇总结果放到2005年存货明细帐中
Insert into ufdata_888_2005..IA_subsidiary (bRdFlag,dvoudate,dKeepDate,iMonth,cInvHead,cVouType,cWhCode,cInvCode,cdepcode,iAInQuantity,iInCost,iAInPrice,
cAccounter,cMaker,cPzID,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10)
select 1,'2004-12-31','2005-01-01',0,null ,34,cwhcode,cinvcode,cdepcode,qu,cost,pr,null,'asuser',
null,null,null,null,null,null,null,null,null,null,null
from ufdata_888_2004..temp03
go
drop table temp02,temp03
go
--清除数量和金额都为0的记录
delete from ufdata_888_2005..ia_subsidiary
where cvoutype='34' and iainquantity=0 and iainprice=0
go |