Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating one field of records from another table
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00581256
Message ID:
00581293
Views:
26
UPDATE: I remember now that you probably can not do this in VFP because subqueries for an UPDATE - SQL are not supported. You will have to set a relation between the 2 tables and do a REPLACE:

select TableA
set order to NameDate && index tag on FieldPersonName + DTOS(SomeDate)
select TableB
set relation to FieldPersonName + DTOS(SomeDate) into TableA
replace all FieldTotal with iif(eof('TableA'), 0, TableA.FieldTotal)

< original reply below >

Funny, I just did this very thing in Oracle today. However, I do not have that code here at home with me. I believe the VFP equivalent will be:

Update TableB set FieldTotal = (select TableA.FieldTotal from TableA where TableA.FieldPersonName + DTOS(SomeDate) in (select FieldPersonName + DTOS(SomeDate) from TableB))

If that is not it, I will post the actual code tomorrow.

>I get the following code to work except it to creates a new record in tableB, but I want it to insert (or is it update?) the values of tableA.fieldtotal into tableB.fieldtotal if the name of the person and the dates are the same in both tables. Presently the following code adds a new record to tableB with all the fields blank except for fieldtotal.
>
> Select tableA.fieldA as fieldtotal ;
> FROM tableA ;
> INNER JOIN tableB ON tableA.fieldpersonname = tableB.fieldpersonname ;
> AND tableA.somedate = tableB.somedate ;
> INTO cursor crsTemp
> SELECT tableB
> append from ( dbf('crsTemp') )
>
>
>Please help me correct this to change the fieldtotal for a specific date and person.
>
>Thank you
>Max
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform