T-SQL 计算固定资产折旧(直线法)
2012-07-21 20:11
169 查看
使用 CTE, 计算固定资产折旧(直线法)。
计算机 0 208.33 5000.00 0.00
计算机 1 208.33 4791.67 208.33
计算机 2 208.33 4583.34 416.66
计算机 3 208.33 4375.01 624.99
计算机 4 208.33 4166.68 833.32
计算机 5 208.33 3958.35 1041.65
计算机 6 208.33 3750.02 1249.98
计算机 7 208.33 3541.69 1458.31
计算机 8 208.33 3333.36 1666.64
计算机 9 208.33 3125.03 1874.97
计算机 10 208.33 2916.70 2083.30
计算机 11 208.33 2708.37 2291.63
计算机 12 208.33 2500.04 2499.96
计算机 13 208.33 2291.71 2708.29
计算机 14 208.33 2083.38 2916.62
计算机 15 208.33 1875.05 3124.95
计算机 16 208.33 1666.72 3333.28
计算机 17 208.33 1458.39 3541.61
计算机 18 208.33 1250.06 3749.94
计算机 19 208.33 1041.73 3958.27
计算机 20 208.33 833.40 4166.60
计算机 21 208.33 625.07 4374.93
计算机 22 208.33 416.74 4583.26
计算机 23 208.33 208.41 4791.59
计算机 24 208.41 0.00 5000.00
DECLARE @Assets TABLE (NAME VARCHAR(20), PurchaseCost MONEY, Period INT) INSERT INTO @Assets SELECT '计算机', 5000, 24 ;WITH SLDepSched (AssetID, [Month], Period -- 固定资产 ,SLDepAmt, SLBookValue, SLCumDep -- 直线法 ) AS ( SELECT NAME, 0, Period ,ROUND(PurchaseCost/Period, 2) -- 直线法折旧额 ,PurchaseCost, CAST(0 AS MONEY) FROM @Assets UNION ALL SELECT AssetID, [Month]+1, Period ,CASE [Month]+1 WHEN Period THEN SLBookValue ELSE SLDepAmt END ,CASE [Month]+1 WHEN Period THEN CAST(0 AS MONEY) ELSE SLBookValue - SLDepAmt END ,CASE [Month]+1 WHEN Period THEN SLCumDep + SLBookValue ELSE SLCumDep + SLDepAmt END FROM SLDepSched WHERE [Month] < Period) SELECT AssetID, [Month], SLDepAmt, SLBookValue, SLCumDep FROM SLDepSched ORDER BY AssetID, [Month]
计算机 0 208.33 5000.00 0.00
计算机 1 208.33 4791.67 208.33
计算机 2 208.33 4583.34 416.66
计算机 3 208.33 4375.01 624.99
计算机 4 208.33 4166.68 833.32
计算机 5 208.33 3958.35 1041.65
计算机 6 208.33 3750.02 1249.98
计算机 7 208.33 3541.69 1458.31
计算机 8 208.33 3333.36 1666.64
计算机 9 208.33 3125.03 1874.97
计算机 10 208.33 2916.70 2083.30
计算机 11 208.33 2708.37 2291.63
计算机 12 208.33 2500.04 2499.96
计算机 13 208.33 2291.71 2708.29
计算机 14 208.33 2083.38 2916.62
计算机 15 208.33 1875.05 3124.95
计算机 16 208.33 1666.72 3333.28
计算机 17 208.33 1458.39 3541.61
计算机 18 208.33 1250.06 3749.94
计算机 19 208.33 1041.73 3958.27
计算机 20 208.33 833.40 4166.60
计算机 21 208.33 625.07 4374.93
计算机 22 208.33 416.74 4583.26
计算机 23 208.33 208.41 4791.59
计算机 24 208.41 0.00 5000.00
相关文章推荐
- T-SQL 计算固定资产折旧(双倍余额法)
- Dynamics AX中财务相关的函数(2)——sln——直线法计算固定资产折旧
- 界面元素查询语句计算页数SQL中增加汇总值描述
- 如何计算应缴个人所得税? 使用SQL,理解SQL
- T-SQL中计算排名问题(考试成绩视图)
- SQL 必知必会·笔记<5>创建计算字段
- sql计算百分比
- 计算执行sql耗时
- 计算一个月有几天 sql
- SQL 计算一個字符串在另一个字符串中出現的次数
- sql 计算地球2个坐标之间的距离
- SQL语句中日期的计算方法大全
- MS SQL Server日期计算
- sql自增长列重新从1计算
- 动态拼接SQL计算公式
- SQL2000里如何计算SQL语句运行的时间
- 某列字符串相加计算的sql语句的写法
- sql 字段先计算后再拿比对的字段进行比对 效率提升100倍
- sql 语句计算方根
- SQL通过日期计算年龄