Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RELATION QUESTION

Status
Not open for further replies.
Jul 7, 2003
95
0
0
US
SELE 1
USE File1 ALIAS firstfile
SELE 2
USE File2 ALIA secondfile
INDEX ON MATCHCODE TAG match
SET ORDER TO MATCHCODE
SELE 1
SET RELATION TO MATCHCODE INTO B


REPLACE ALL A.MYFIELD1 WITH B.MYFIELD2 for A.MATCHCODE= B.MATCHCODE


**** Should't this statement update all file1 FIELDS from file2 and not just one record as seems to be happening?
 
When you are activating the Index on File2 you are not using the correct TAG name.

USE File1 IN 0 ALIAS firstfile
USE File2 IN 0 ALIAS secondfile

SELECT SecondFile
INDEX ON MATCHCODE TAG match
SET ORDER TO MATCHCODE && <<-- Wrong Reference

Instead, you should:
SET ORDER TO MATCH

Then (assuming that you have a field MatchCode in File1):

SELECT FirstFile
SET RELATION TO MatchCode INTO SecondFile
REPLACE ALL FirstFile.MYFIELD1 WITH SecondFile.MYFIELD2;
FOR FirstFile.MatchCode = SecondFile.MatchCode

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
INDEX ON MATCHCODE TAG match
SET ORDER TO MATCHCODE && <<-- Wrong Reference

That was my typo.. the order is typed correct in the original program. I still get only one record updated.

Here is the actual code I used...

CLOSE ALL
CLEAR
SET SAFETY OFF
SELE 1
USE kerryking ALIAS kerry
SELE 2
USE automaster ALIA auto
INDEX ON match TAG match
SET ORDER TO MATCH
SELE 1
SET RELATION TO match INTO B

 
Have you used SET STEP ON to 'break' the program at the point just before the REPLACE command?

If you have, you should be able to interactively BROWSE both the "Parent" (file1) table and "Child" (file2) table to see if the RELATION is working as expected when you scroll through the Parent records.

It sounds as though the RELATION is not setup and/or working correctly. Or perhaps, the Match fields are not 'matching' (check field size & type, etc.).

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Thanks for you help. I don't know what I differently, but its working now.
 
powerprinting,

There must be something else at play here...I mean the basic premise of what you have described (your code has not been very consistent here so it is hard to tell) will work. Run this example in VFP:
Code:
SELECT 1
CREATE CURSOR kerryking (match I, test c(30))
INSERT INTO kerryking (match, test) VALUES (1, "HELLO WORLD")
INSERT INTO kerryking (match, test) VALUES (2, "HELLO WORLD")
INSERT INTO kerryking (match, test) VALUES (3, "HELLO WORLD")

SELECT 2
CREATE CURSOR automaster (match I, test c(30))
INSERT INTO automaster (match, test) VALUES (1, "GOODBYE WORLD")
INSERT INTO automaster (match, test) VALUES (2, "GOODBYE WORLD")
INSERT INTO automaster (match, test) VALUES (3, "GOODBYE WORLD")

INDEX ON match TAG match
SET ORDER TO MATCH
SELE 1
SET RELATION TO match INTO B

REPLACE ALL A.test WITH B.test for A.MATCH = B.MATCH

BROWSE && all recs in kerryking now say GOODBYE WORLD

boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
[/sup]
 
I've been playing with this code for my own purposes and was wondering something... when table a has say 10000 records and table b has maybe 1000 records that contain the value to be replaced, why does the odometer register 10000 record replaced and not 1000?
 
Fox will scan all 10,000 records of table 'a' to see if there are matches in table 'b' for all of them. It doesn't know beforehand if there are 1,000 or 10,000 matches until it reads the entire file.
So the odometer is based on table 'a', not 'b'.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top