Skip to content
Advertisement

How to check the current row with next row and update the current row not using while loop and cursor

Is there any way other than using the cursor or while loop to check the current row with the next row and update the current row and do this through all rows in the data set?

For example, this is the table we have:

This while loop go through each row and update @new_value based on some conditions and then check with the next row.

I would like to see if there is any way not to use a loop or cursor and get the same result.

Advertisement

Answer

Here it is in recursive cte

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement