Skip to content
Advertisement

Update next record based on last updated record

I’m struggling to find a solution to update the calculation in the same table based on last updated records order by select column.

I have tried LEAD & LAG, but can’t give complete solution of my problem.

I tried below query but didn’t succeed.

I can use a while loop, but there are more than 50K records. I want to do it in the fastest possible way.

Advertisement

Answer

Hmmm . . . If you want a select, then you want a cumulative sum:

If you actually want an update (as the title to the question suggests), you can use this in an updatable CTE>

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