Fill the NULLS from the previous VALUE

editolis

Panathinaikos Fun
Local time
Today, 23:57
Joined
Oct 17, 2008
Messages
107
Hi All,

I need some help.

I Want to fill the NULLS from the PREVIOUS fields of my table.

EXAMPLE:

ID – My Field
1 - USA
2 -
3 -
4 - GERMANY
5 -
6 - ENGLAND
7 –
etc

I WANT THIS:

ID – My Field
1 - USA
2 - USA
3 - USA
4 - GERMANY
5 - GERMANY
6 - ENGLAND
7 - ENGLAND

Any suggestion?

Thank you in advance
 
This will do it - provided your ID is in numerical order. The key is having the < sign instead of an = sign in your join.

Code:
UPDATE (SELECT Table1.id, Table1.field1
   FROM Table1
   WHERE Not Table1.field1 Is Null) AS RS 
INNER JOIN Table1 ON RS.id < Table1.id 
SET Table1.field1 = RS.FIELD1
WHERE Table1.field1 Is NuLL;
 
This is the solution.

Thank you redneckgeek.
 

Users who are viewing this thread

Back
Top Bottom