zoukankan      html  css  js  c++  java
  • 用友U8固定资产总账重算语句

    用友U8各版本如果出现固定资产模块账表查询时数据有误,但是卡片管理中数据正确的情况下,在查询分析器中执行下述语句,注意下面红字部分,需要逐月修改执行。

    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=substring(db_name(),8,3), @acc_year=substring(db_name(),12,4), @iperiod=3 -----修改成需要重算总账的会计月份---

    SELECT @Begin=[dBegin], @end =[dEnd]FROM [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 @iperiod>12 return

     insert #fq

     SELECT max(C.[sCardID])FROM [fa_Cards] C

     WHERE  (

       (c.dInputDate<@Begin) AND

       (c.dTransDate<@Begin Or c.dTransDate Is Null) AND 

      (c.dDisposeDate<@Begin 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

       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.dblMonthvalue<>isnull(Dv,0)) and

       T.iperiod=@iperiod

    --取月末有效卡片序号数据,计算月末累计折旧数据

    truncate table #fq

    insert #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

      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.dblDepr<>isnull(DP,0) or t.dblvalue<>isnull(Dv,0)) and

     T.iperiod=@iperiod

    truncate table #fq

    --取本月新增或变动有效卡片序号数据,计算本月折旧变动情况

    insert #fq

    SELECT C.[sCardID]

    FROM  [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_total

    set [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.iopttype<>3 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.[sCardID]

      group by D.[sDeptNum],C.[sTypeNum]

     ) as A

     on T.[sDeptNum]=a.[sDeptNum] and T.[sTypeNum]=a.[sTypeNum]

    where   T.iperiod=@iperiod and

    ([dblTransOutDeprTotal]<>isnull(outdt,0)  or  [dblTransInDeprTotal]<>isnull(indt,0))

    drop table #fq

  • 相关阅读:
    2020 CCPC-Wannafly Winter Camp Day6 ---I. 变大!
    Codeforces 1295F Good Contest
    2020 CCPC-Wannafly Winter Camp Day6 ---A. Convolution
    centos下kubernetes+flannel部署(旧)
    无网络centos7中部署kubernetes
    利用Openvswitch实现不同物理机中的Docker容器互连
    docker-py的配置与使用
    通过Docker配置DNS服务器
    在 OS X Yosemite 中部署Mesos
    Docker初识
  • 原文地址:https://www.cnblogs.com/martian6125/p/9631004.html
Copyright © 2011-2022 走看看