我在SSRS固定资产折旧报告中面临一个问题,即如何计算折旧价值? 我用这个公式计算((ACQUISITIONPRICE / Depreciation Period)* Depreciation Remain)但值不正确让我们举一个例子,
由assetid,ASSETGROUP,NAME,LIFETIME,LIFETIMEREST,ACQUISITIONPRICE
BLDRNV53,R楼,防水工程,60,-57,370
SQL查询中的计算:
SELECT ASSETTABLE.ASSETID, ASSETTABLE.ASSETGROUP, ASSETTABLE.NAME, (ASSETBOOK.LIFETIMEREST * (ASSETBOOK.ACQUISITIONPRICE / ASSETBOOK.LIFETIME)) as AccDep
FROM ASSETBOOK INNER JOIN
ASSETTABLE ON ASSETBOOK.ASSETID = ASSETTABLE.ASSETID AND ASSETBOOK.DATAAREAID = ASSETTABLE.DATAAREAID
WHERE (ASSETBOOK.DEPRECIATION = 1) AND ASSETBOOK.STATUS = 1
实施例: ((370/60)* -57)= -351.5但系统报告正在计算-350.550有0.95差异,整个折旧值有这么小的差异。
请帮助
答案 0 :(得分:2)
我不明白-350.550
值的来源。我无法在我的测试中重现它。
我的建议是确保ACQUISITIONPRICE
的列数据类型准确地表示存储在数据库中的数据类型。鉴于名称,我假设存储的值代表某种类型的货币。 decimal数据类型可能是一个不错的选择,比如DECIMAL(10,2)。根据需要提高精度以满足您的要求。
在舍入值之前执行所需的所有计算,仅在表示层中需要时进行舍入。
示例T-SQL用于演示不同数据类型对结果的影响:
-- create temporary table, columns with integer datatype
IF OBJECT_ID('tempdb.dbo.#Asset') IS NOT NULL
DROP TABLE #Asset;
CREATE TABLE #Asset (
LifetimeRest INTEGER NOT NULL,
AcquisitionPrice INTEGER NOT NULL,
Lifetime INTEGER NOT NULL
);
-- load sample data
INSERT INTO #Asset VALUES (-57, 370, 60);
-- result is -342 with integer datatype and no conversion
SELECT
IntegerCalculation = LifetimeRest * (AcquisitionPrice / Lifetime)
FROM #Asset;
-- result is -351.500000 is with dynamic decimal conversion
SELECT
DynamicDecimalCalculation = LifetimeRest *
(CAST(AcquisitionPrice AS DECIMAL) / Lifetime)
FROM #Asset;
-- change price datatype to decimal with consistent precision and scale
ALTER TABLE #Asset ALTER COLUMN AcquisitionPrice DECIMAL(10, 2);
-- result is -351.4999620 with static decimal precision and scale,
-- and no on the fly conversion
SELECT
StaticDecimalCalculation = LifetimeRest * (AcquisitionPrice / Lifetime)
FROM #Asset;
-- cleanup
IF OBJECT_ID('tempdb.dbo.#Asset') IS NOT NULL
DROP TABLE #Asset;
答案 1 :(得分:0)
缺少的等式是固定资产刮削值,该示例中的资产为1.000,因此等式为(((Acquisition Price - Scrape Value) / Depreciation Period) * Depreciation Remain)
让我们用数字填写: (((370 - 1)/ 60)* -57)= -350.550
感谢大家的帮助