473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VFP update from another table

Not sure if this is the right location for this question.
I Saw several previous FP questions in this Group and did not see one for
VFP....

If this is the wrong group, please direct me appropriately.

I have two tables and I would like to update a field in table1 based on data
in table2. Here is an example of what I thought I could do based on SQL .

update employee
set salary = e.salary + b.amount
from employee e, bonus b
where e.empid = b.empid and e.company = b.company.

I have tried several updates from a google search including joins, and sub
selects to no avail.

Any assistance would be greatly appreciated.

Nov 21 '05 #1
3 6580
Chris,

If you aren't using Visual Studio.NET, then I would suggest the next time
you visit the newsgroup 'microsoft.public.fox.programmer.exchange'.

In answer to your question, you can't do that in VFP, yet. The method in
FoxPro would be command code.
Create an index of str(employee.id ) + employee.company on the employee
table.
Set the order in employee to your index tag.
Select the bonus table.
Then create a relationship between the tables:

SET RELATION TO str(Bonus.id) + bonus.company INTO Employee ADDITIVE
SET SKIP TO Employee

REPLACE ALL employee.salary with employee.salary + bonus.amount
That should do it for you.

M. Miller


"Chris Morton" <Chris Mo****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
Not sure if this is the right location for this question.
I Saw several previous FP questions in this Group and did not see one for
VFP....

If this is the wrong group, please direct me appropriately.

I have two tables and I would like to update a field in table1 based on data in table2. Here is an example of what I thought I could do based on SQL .

update employee
set salary = e.salary + b.amount
from employee e, bonus b
where e.empid = b.empid and e.company = b.company.

I have tried several updates from a google search including joins, and sub
selects to no avail.

Any assistance would be greatly appreciated.

Nov 21 '05 #2
Hi Chris,

You've left out a lot of details. Are you working in Visual FoxPro (if so,
you'll be better off posting to a Fox newsgroup), or sending SQL
Pass-through from a .NET app? Are you using ODBC or OLE DB? What's the
version of the driver/data provider you're using? There have been recent
improvements in the FoxPro and Visual FoxPro OLE DB data provider, which is
downloadable from
http://msdn.microsoft.com/vfoxpro/do...s/default.aspx.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@msn.com www.cindywinegarden.com
"Chris Morton" <Chris Mo****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
Not sure if this is the right location for this question.
I Saw several previous FP questions in this Group and did not see one for
VFP....

If this is the wrong group, please direct me appropriately.

I have two tables and I would like to update a field in table1 based on
data
in table2. Here is an example of what I thought I could do based on SQL .

update employee
set salary = e.salary + b.amount
from employee e, bonus b
where e.empid = b.empid and e.company = b.company.

I have tried several updates from a google search including joins, and sub
selects to no avail.

Any assistance would be greatly appreciated.

Nov 21 '05 #3
Hi Chris,

Sorry I'm late to this thread so I hope you see this. Here's VB code that
works, and needless to say the same SQL works in VFP9, which has recently
been released.

Option Explicit On
Option Strict On

Imports System
Imports System.Data
Imports System.Data.OleDb

Module Module1
Sub Main()
Try

'-- Download and install the latest VFP OLE DB data provider
'-- from
http://msdn.microsoft.com/vfoxpro/do...s/default.aspx
'-- This example assumes you already have a c:\Temp directory
'-- For free tables use "Data Source = C:\MyFolder"
'-- For a DBC use "Data Source = C:\MyFolder\MyDBC"
'-- When there are spaces in the path use "" around it.
'-- Note also that you can surround a quoted string with "", '',
or [] in VFP.
Dim conn As OleDbConnection
conn = New OleDbConnection("Provider=VFPOLEDB.1;Data
Source=C:\Temp;")
conn.Open()

'-- Lets create some data to work with
Dim cmd1 As New OleDbCommand("Create Table Employee (EmpID I,
Company I, Salary I)", conn)
Dim cmd2 As New OleDbCommand("Insert Into Employee Values (1, 1,
2000)", conn)
Dim cmd3 As New OleDbCommand("Create Table Bonus (EmpID I,
Company I, Amount I)", conn)
Dim cmd4 As New OleDbCommand("Insert Into Bonus Values (1, 1,
100)", conn)
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
cmd3.ExecuteNonQuery()
cmd4.ExecuteNonQuery()

'-- Now let's update our data
Dim cmd5 As New OleDbCommand( _
"Update Employee Set Salary = e.Salary + b.Amount " & _
"From Employee e, Bonus b " & _
"Where ((e.EmpID = b.EmpID) And (e.Company = b.Company))",
conn)

''-- Now let's update our data
'Dim cmd5 As New OleDbCommand( _
' "Update Employee Set Salary = e.Salary + 100 " & _
' "From Employee e " & _
' "Where ((e.EmpID = 1) And (e.Company = 1))", conn)

cmd5.ExecuteNonQuery()

'-- Now let's see what the data looks like
Dim da As New OleDbDataAdapter("Select * From Employee", conn)
Dim ds As New DataSet
da.Fill(ds)

MsgBox("Salary = " & ds.Tables(0).Rows(0).Item(2).ToString())

Catch ex As Exception
MsgBox(ex.ToString())
End Try

End Sub
End Module

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@msn.com www.cindywinegarden.com
"Chris Morton" <Chris Mo****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
Not sure if this is the right location for this question.
I Saw several previous FP questions in this Group and did not see one for
VFP....

If this is the wrong group, please direct me appropriately.

I have two tables and I would like to update a field in table1 based on
data
in table2. Here is an example of what I thought I could do based on SQL .

update employee
set salary = e.salary + b.amount
from employee e, bonus b
where e.empid = b.empid and e.company = b.company.

I have tried several updates from a google search including joins, and sub
selects to no avail.

Any assistance would be greatly appreciated.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.