NEWBIE: replacing a field from one table to another
Quote:
>I am trying to write a program that will replace the contents of a field in
>one table to a field in another table. Both tables are indexed on the
>userid field. I can successfully replace the first record but all
>subsequent records are ignored. I tried adding a scan/endscan but it didn't
>help. Any suggestions?
>set exclusive off
>open data data1
>use table1.dbf in 0
>use table2.dbf in 0
>replace all table1.lastname with table2.dept for table1.userid=table2.userid
Try this:
USE table1 IN 0 INDEX TAG userid
USE table2 IN 0 INDEX TAG userid
SELECT table1
GO TOP
DO WHILE ! EOF([table1])
SELECT table2
IF SEEK(table1.userid, [table2])
SELECT table1
REPLACE table1.lastname WITH table2.dept
ENDIF SEEK(table1.userid, [table2])
SKIP IN table1
ENDDO WHILE ! EOF([table1])
I prefer DO WHILE in this situation because I have seen SCAN get
confused while doing something like this.
Hope this helps...
Christopher Reed
"The oxen are slow, but the earth is patient."