Skip to content
Advertisement

SQL SERVER Replace Null

I have a tsql query like that:

My result :

I want to change null value with null value’s last one numeric value. I want to see that:

But i dont want to use while loop. How can i do it ?

Advertisement

Answer

If the values are increasing, use a cumulative max:

If the code is not strictly increasing, then you can do this in two steps:

Given that this is a table variable, I’m guessing that you don’t really want to update it. But if you do:

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