Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating with previous records

Status
Not open for further replies.

proximity

Technical User
Sep 19, 2002
132
GB
I have a table with the following example data:
Id | field1
1 | abc
2 |
3 | def
4 |
5 | dtg
6 |
7 | abc
Is there a way using sql only to fill in the nulls, as in the example below, with the value of the row above it?
Id | field1
1 | abc
2 | abc
3 | def
4 | def
5 | dtg
6 | dtg
7 | abc

Thanks in anticipation . . .

--
Steven
 
this should give you a hint:

select * form table a
join table b on a.id = b.id-1

then, when you see what you want you append update to it
 
Hi,

Many thanks for your reply, but it did not quite work as I wanted. Please find below a better description of my requirement:

Table B is the same as Table B, with Table B representing what the results should be. So, every time there is a null in A, it gets populated with whatever the previous non-null value was above it!!!! The [null] value is just a place-holder so this post displays correctly.


A B
ID Field1 Field2 ID Field1 Field2
46 @I05 TPGA21 46 @I05 TPGA21
48 @Y17 TPGA05 48 @Y17 TPGA05
50 HH53 TRKMAN 50 HH53 TRKMAN
59 #Y03 TPGA41 59 #Y03 TPGA41
60 [null] TPGA24 60 #Y03 TPGA24
62 #Y05 TPGA24 62 #Y05 TPGA24
63 [null] TPGA41 63 #Y05 TPGA41
65 #Y07 TPGA03 65 #Y07 TPGA03
66 [null] TPGA41 66 #Y07 TPGA41
67 [null] TPGA30 67 #Y07 TPGA30
68 [null] TPGA30 68 #Y07 TPGA30
69 [null] TPGA30 69 #Y07 TPGA30
70 [null] TPGA23 70 #Y07 TPGA23
72 #Y09 TPGA22 72 #Y09 TPGA22
73 [null] TPGA22 73 #Y09 TPGA22
74 [null] TPGA36 74 #Y09 TPGA36
75 [null] TPGA24 75 #Y09 TPGA24
77 #Y11 TPGA36 77 #Y11 TPGA36
78 [null] TPGA37 78 #Y11 TPGA37
79 [null] TPGA41 79 #Y11 TPGA41

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top