If @startposition = 1 and @endposition = 3 then Output column would be something like following
DID-------ID--------Value---------Output
1---------1-----------2------------2+12+45 = 59
1---------2-----------12-----------12+45+8 = 65
1---------3-----------45-----------45+8+63
1---------4-----------8------------8+63+24
1---------5-----------63-----------63+24
1---------6-----------24-----------24
2---------1-----------89-----------89+20+46
2---------2-----------20-----------20+46+96
2---------3-----------46-----------46+96
2---------4-----------96-----------96
I have to do it in one query without using loop....