how to scan each row of a table, and update current row based on previous row?

Viewed 104

I need to update the current row using the following logic:

  1. if current row is null, then set it as previous row
  2. if current row is not null, then no action

the 1st row is not null, then NULL appears randomly

Those NULLs need to be updated using the logic previously mentioned

e.g.

 1. 1
 2. null
 3. null
 4. 2
 5. null
 6. null

needs to be updated as

 1. 1
 2. 1
 3. 1
 4. 2
 5. 2
 6. 2

How to do it in SQL?

Thanks r

5 Answers
Related