I have a dataset with columns:
What I need to do is to create a loop with such conditions:
- For Index = 1
- if Column1 >= 1 then Column2 = 1 and Column3 = Column1 - 1
- if Column1 < 1 then Column 2 = 0 and Column3 = 0
- For Index > 1
- if Column1 + Column3 (from previous iteration!) >=1 then Column2 = 1 and Column3 = Column1 + Column3 (from previos iteration!) - 1
- if Column1 + Column3 (from previous iteration) < 1 then Column2 = 0 and Column3 = 0
I need to update this column one row at the time, starting with Index = 1. I have tried to start with such WHILE loop:
WHILE (SELECT COUNT(*) FROM #TABLE WHERE Column2 IS NULL) > 0
UPDATE TOP (1) #TABLE
SET ...
And I simply can't achieve my desired outcome like this:
And of course I really, really want to avoid using Cursor. Thank you for your help!

