dealing with calculations

  • 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

  • SELECT *

    &nbsp&nbsp&nbsp&nbsp,T.Depreciation +

    &nbsp&nbsp&nbsp&nbspCOALESCE

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT SUM(T1.Depreciation)

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM YourTable T1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T1.[ID] < T.[ID]

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp, 0

    &nbsp&nbsp&nbsp&nbsp) AS AccummulativeDepreciation

    FROM YourTable T

  • 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