August 19, 2008 at 5:04 am
hi
i have a table which look like this:
IDDepreciation
510040
547960
58585-19079.347
62466-113.57
66291-113.57
70143-113.57
74025-113.57
77933-113.57
81849-113.57
on my script i need to calculate a Accummulative Depreciation on another field and the rule is on the first entry the Depreciation will remain the same, the second entry should take the value from the prevous entry add it to the current entry i.e for ID 51004 and 54796 AccumDepr will be 0 cause there's no Depreciation value this id 58585 should equal to 19079.347 cause there's no previous depr, and on ID 62466 my AccumDepr should be (-19079.347) + (-113.57) = -19192.91 and the next ID should be -19192.91 + -113.57 = -19306.48 and so forth...
please help
August 19, 2008 at 6:58 am
SELECT *
    ,T.Depreciation +
    COALESCE
    (
        (
            SELECT SUM(T1.Depreciation)
            FROM YourTable T1
            WHERE T1.[ID] < T.[ID]
        )
        , 0
    ) AS AccummulativeDepreciation
FROM YourTable T
August 19, 2008 at 7:19 am
thanks Ken, will work on it now and see if it's works
thanks again
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply