Reputation: 105
I'm trying to do this in VPF6:
Update Table1 From table2 Where table1.id = table2.id ;
Set table1.name = table2.name
I only find solution for VFP9 from @EdPecyna : visual foxpro - need to update table from another table
Thanks a lot
Upvotes: 0
Views: 903
Reputation: 23797
In VFP6, you need to do it in a loop as Alan B. showed already.
However, you can use the style you tried even from VFP5 or VFP3, if you use the VFP9 engine via VFPOLEDB. This is sometimes very useful allowing you to execute SQL that is not available in older versions. ie:
Local cn
cn = createobject('adodb.connection')
cn.ConnectionString = 'Provider=VFPOLEDB;Data Source=c:\MyDataFolder\'
cn.Open()
cn.Execute('set exclusive off')
cn.Execute('Update table1 set name=table2.name from table2 where table1.Id=table2.id')
cn.Close()
Upvotes: 1
Reputation: 4288
You can't do it in one command in VFP 6 because the SQL engine in that version doesn't support 'UPDATE FROM'. So you have to write some code.
Assuming 'id' is unique in both tables:
select table2
scan
update table1 where table1.id = table2.id set table1.name = table2.name
endscan
Upvotes: 2