解决用友U8固定资产对账不平.doc_第1页
解决用友U8固定资产对账不平.doc_第2页
解决用友U8固定资产对账不平.doc_第3页
解决用友U8固定资产对账不平.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

begin TRANSACTION kk-创建临时表CREATE TABLE #fq(sCardID int ,PRIMARY key nonCLUSTERED (sCardID) commit TRANSACTION kk-初始化定义变量declare Begin datetime,end datetime,iperiod int, acc_id varchar(10), acc_year varchar(10)declare SQL nchar(2000)-得到当前本数据库的有关信息select acc_id=999, acc_year=2013, iperiod=1, Begin=2013-01-01 00:00:00.000, end=2013-01-31 00:00:00.000-修改成需要重算总账的相关信息-SELECT Begin=dBegin, end =dEndFROM UFSystem.dbo.UA_Period - where cAcc_Id=acc_id and iYear =acc_year and iId=iperiod-Select acc_id,acc_year,iperiod,Begin,end-取月初有效卡片序号数据,计算月初累计折旧数据if iperiod12 return insert #fq SELECT max(C.sCardID)FROM fa_Cards C WHERE ( (c.dInputDateBegin) AND (c.dTransDateBegin Or c.dTransDate Is Null) AND (c.dDisposeDateBegin Or c.dDisposeDate Is Null) ) group by C.sCardNum -Set SQL= update fa_total set dblMonthDeprTotal=isnull(DT,0) ,dblMonthvalue=isnull(Dv,0) FROM fa_total T left join ( Select D.sDeptNum,C.sTypeNum, sum(D.dblValue) DV, sum(case iperiod-1 when 0 then dblDeprT1-dblDepr1 when 1 then dblDeprT1 when 2 then dblDeprT2 when 3 then dblDeprT3 when 4 then dblDeprT4 when 5 then dblDeprT5 when 6 then dblDeprT6 when 7 then dblDeprT7 when 8 then dblDeprT8 when 9 then dblDeprT9 when 10 then dblDeprT10 when 11 then dblDeprT11 else 0 end) DT from fa_Cards C JOIN fa_Cards_Detail D ON D.sCardID=C.sCardID JOIN fa_DeprTransactions_Detail P ON C.sCardNum=P.sCardNum AND D.sDeptNum=P.sDeptNum join #fq on #fq.sCardID=C.sCardID WHERE C.dDisposeDate is null and iyear=acc_year group by D.sDeptNum,C.sTypeNum ) as A on T.sDeptNum=a.sDeptNum and T.sTypeNum=a.sTypeNum where (T.dblMonthDeprTotal isnull(DT,0) or T.dblMonthvalueisnull(Dv,0) and T.iperiod=iperiod -取月末有效卡片序号数据,计算月末累计折旧数据truncate table #fqinsert #fq SELECT max(C.sCardID)FROM fa_Cards C WHERE ( (c.dInputDate=end) AND (c.dTransDate=end Or c.dTransDate Is Null) AND (c.dDisposeDate=end Or c.dDisposeDate Is Null) ) group by C.sCardNum-Set SQL= update fa_total set dblDeprTotal=isnull(DT,0),dblDepr=isnull(DP,0) ,dblvalue=isnull(Dv,0)FROM fa_total T left join ( Select D.sDeptNum,C.sTypeNum, sum(D.dblValue) DV, sum( case iperiod when 1 then dblDeprT1 when 2 then dblDeprT2 when 3 then dblDeprT3 when 4 then dblDeprT4 when 5 then dblDeprT5 when 6 then dblDeprT6 when 7 then dblDeprT7 when 8 then dblDeprT8 when 9 then dblDeprT9 when 10 then dblDeprT10 when 11 then dblDeprT11 when 12 then dblDeprT12 else 0 end ) DT , sum( case iperiod when 1 then dblDepr1 when 2 then dblDepr2 when 3 then dblDepr3 when 4 then dblDepr4 when 5 then dblDepr5 when 6 then dblDepr6 when 7 then dblDepr7 when 8 then dblDepr8 when 9 then dblDepr9 when 10 then dblDepr10 when 11 then dblDepr11 when 12 then dblDepr12 else 0 end) DP from fa_Cards C JOIN fa_Cards_Detail D ON D.sCardID=C.sCardID JOIN fa_DeprTransactions_Detail P ON C.sCardNum=P.sCardNum AND D.sDeptNum=P.sDeptNum join #fq on #fq.sCardID=C.sCardID WHERE C.dDisposeDate is null and iyear=acc_year group by D.sDeptNum,C.sTypeNum ) as A on T.sDeptNum=a.sDeptNum and T.sTypeNum=a.sTypeNum where (T.dblDeprTotal isnull(DT,0) or t.dblDeprisnull(DP,0) or t.dblvalueisnull(Dv,0) and T.iperiod=iperiodtruncate table #fq-取本月新增或变动有效卡片序号数据,计算本月折旧变动情况insert #fq SELECT C.sCardIDFROM fa_Cards C WHERE ( (c.dInputDate between begin and end) or (c.dTransDate between begin and end)or (c.dDisposeDate between begin and end) ) update fa_totalset dblTransInDeprTotal=indt,dblTransOutDeprTotal=(outdt)FROM fa_total T left join ( Select D.sDeptNum,C.sTypeNum, sum(d.dblTransInDeprTCard) inDt, sum(d.dblTransOutDeprTCard+ case when c.iopttype3 then 0 else case iperiod when 1 then p.dblDepr1 when 2 then p.dblDepr2 when 3 then p.dblDepr3 when 4 then p.dblDepr4 when 5 then p.dblDepr5 when 6 then p.dblDepr6 when 7 then p.dblDepr7 when 8 then p.dblDepr8 when 9 then p.dblDepr9 when 10 then p.dblDepr10 when 11 then p.dblDepr11 when 12 then p.dblDepr12 else 0 end end ) outDT from fa_Cards C JOIN fa_Cards_Detail D ON D.sCardID=C.sCardID JOIN fa_DeprTransactions_Detail P ON C.sCardNum=P.sCardNum AND D.sDeptNum=P.sDeptNum join #fq on #fq.sCardID=C.s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论