Querying sql 2000 using values from previous rows

RFREITAS 2016-02-25 16:28:19

Hi there,

I'm bumping my head around this for a few days. What I need is to calculate several discounts aplied cascading to one initial value per document, per line
The catch is I'm using SQL 2000 server , so no with cte code. ๐Ÿ™

alt text

In line 2 The final value is the final value from line 1 multipled by the percentage of line 2.

Is this even possible? I can have a multiple (n) discounts per line.

I took a look at running totals, but the values is changing from one line to another, so summing is not the way.

I need the Discount and Final columns by query. I have made a column rownumber on the left, but that only worked for two lines of discounts… ๐Ÿ™

Please help. Thank you.

RichardBrianSmith 2016-03-13 22:29:46
Very Excel. In SQL I would persist Final in a variable (@final) inside a while loop.