Question : Problem using update command in Foxpro

I am trying to update a cursor from another cursor using the following update command:

upda file1 set file1.field1=file2.field1 wher betw(file1.rec, file2.begrec, file2.endrec)

"rec" is a field that has been replaced by recno()

"begrec" is the beginning record, and "endrec" is the ending record, so that it updates file1 from file2, based on a range between two records. However, nothing is getting replaced. Is this type of criteria able to work in Foxpro?

Answer : Problem using update command in Foxpro

Your update does miss a FROM clause. And if you would add it, you can't read file2.begrec and file2.endrec from one record of file2 and at the same time traverse file2 records to update file1, in short your logic is ill.

If you really want to update a range of file1 records rom the same range of file2 records, you'll first need to store beginrec and endrec in a variable each, then do your logic this way...

However then I assume your two files are a vertical split table with 1:1 records and you need to be cautious, that their record number really relates the right records to each other. It's recommended to have an ID column in both file1 and file2 then to have a stronger and more mandatory relation

Bye, Olaf.

PS: @pcelba: you can relate two dbfs based on the recno without any index.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
use file1 in 0
use file2 in 0

* locate file2 record determining the record range
lnBeginrec =  file2.begrec
lnEndrec = file2.endrec

select file1
set relation to recno() into file2
replace field1 with file2.field1 for between(recno(),lnStartrec,lnEndrec) in file1
Random Solutions  
 
programming4us programming4us