Search code examples
visual-foxprofoxpro

updating a table in VFP


There are two tables in my database. I am trying to update a column in table2 by setting it equal to one of the columns in table1. I've already looked at this answer visual foxpro - need to update table from another table And tried to do this on my code, however, I kept having a syntax error on UPDATE table2. Why? Here is what I have.

ALTER TABLE table2;
ADD COLUMN base2 B(8,2);
UPDATE table2
WHERE table2.itemid=table1.itemid from table1;
SET table2.base2=table1.base;

Solution

  • Using 'standard' VFP language syntax and RELATED Tables, you could quite easily do the following:

    USE Table1 IN 0 EXCLUSIVE
    SELECT Table1
    INDEX ON ID TAG ID  && Create Index on ID field
    USE Table2 IN 0
    SELECT Table2
    SET RELATION TO ID INTO Table1
    REPLACE ALL Table2.ID WITH Table1.ID FOR !EMPTY(Table2.ID)  
    

    You might want to spend some time looking over the free, on-line tutorial videos at: Learn Visual Foxpro @ garfieldhudson.com
    The videos named:
    * Building a Simple Application - Pt. 5
    and
    * Q&A: Using Related Tables In A Report
    Both discuss using VFP's language to work with Related Tables

    Good Luck