Alejandro-2988924
Alejandro-2988924

Reputation: 105

update from another table vfp6

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

Answers (2)

Cetin Basoz
Cetin Basoz

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

Alan B
Alan B

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

Related Questions