Simple question?  
Author Message
General Fault





PostPosted: Visual FoxPro General, Simple question? Top

I have an ID field in a PRODUCT table, now, suppose that I have 7 products with an ID of "100", what I want to do is to change the ID values of all the products with and ID of "100".

Everything I 've done until now hasn't worked.

First I tried this:

SELECT PRODUCT

SET ORDER TO TAG id ASCENDANT

GO TOP

IF SEEK(100,'PRODUCT') THEN

DO WHILE NOT EOF()

REPLACE product.id WITH someothervalue

SKIP

ENDDO

ENDIF

The above code doesn't seem to work as it only changes the first encountered record.

Then I tried to use:

SELECT PRODUCT

GO TOP

SCAN FOR product.id = 100

REPLACE product.id WITH someothervalue

ENDSCAN

This threw me the same results as before.

I also have used the REPLACE command with scope clauses like REST, NEXT, etc.

Any input about this would be really appreciated



Visual FoxPro2  
 
 
MarciaAkins





PostPosted: Visual FoxPro General, Simple question? Top

SELECT PRODUCT

SET ORDER TO TAG id ASCENDANT

GO TOP

IF SEEK(100,'PRODUCT') THEN

DO WHILE NOT EOF()

REPLACE product.id WITH someothervalue

SKIP

ENDDO

ENDIF

The above code doesn't seem to work as it only changes the first encountered record.

This is exactly what I would expect to happen.

After you replace the first ID, you fall out of the SCAN WHILE look because the WHILE condition is no longer true.

This really should work for you:

REPLACE ID WITH SomeOtherValue FOR ID = 100 IN Product

However, I would change the field name to something like Product_id because ID is a reserved work and may come back to bite you.