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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacement problem

Status
Not open for further replies.

zanga

Technical User
Jun 6, 2011
1
RO
I'm trying to replace somme values from one database to another one(in empty cells).
I'm using the folowing code:
CLOSE ALL
USE d:\rom\int IN a
USE d:\rom\dbromex IN b

IF a.codu=b.cui
replace a.telm2 WITH b.tel2 FOR EMPTY(a.telm2)
ENDIF

But nothing happens.
What am I missing?
Thanks !
 
First, there is no 'connection' between your 2 data tables (yes - they misused used the term 'database' WAY back when, but they are data tables[/U, not databases) - therefore a record-by-record evaluation of the contents of a.teim2 nor acquisition of the record-specific value of b.tel2 cannot be done.

Either establish a RELATION between the 2 tables or utilize some other means (such as SCAN/ENDSCAN) to cycle through the records in one table and put the values into the other table.

And you so not SELECT your 'parent' table before you attempt the REPLACE.

The following code examples might be possibilities...

Code:
* --- Index approach (preferred approach) ---
USE d:\rom\int IN 0 ALIAS a
USE d:\rom\dbromex IN 0 ALIAS b EXCLUSIVE
* --- Create INDEX on 'child' table ---
SELECT b
INDEX ON cui TAG cui

* --- Select the 'parent' table ---
SELECT a
* --- Establish RELATION between 2 tables ---
SET RELATION TO codu INTO b
* --- Use that RELATION to 'control' the REPLACE on matching records ---
REPLACE ALL a.telm2 WITH b.tel2 FOR EMPTY(a.telm2)
* --- Terminate the RELATION ---
SET RELATION TO

<do whatever>

Code:
* --- SCAN/ENDSCAN approach (alternate approach) ---
USE d:\rom\int IN 0 ALIAS a
USE d:\rom\dbromex IN 0 ALIAS b

* --- Only SCAN records where a.telm is EMPTY() ---
SELECT a
SCAN FOR EMPTY(a.telm2)
   m.codu = a.codu

   SELECT b
   LOCATE FOR b.cui = m.codu
   IF FOUND()
      * --- Match Found, Now acquire 'replace' value from b ---
      m.tel2 = b.tel2
      
      * --- Replace value in a ---
      SELECT a
      REPLACE a.telm2 WITH m.tel2
   ENDIF  && IF FOUND()

   SELECT a
ENDSCAN

<do whatever>

You might want to look over the free tutorial videos at:
NOTE - while these tutorials are regarding Visual Foxpro, the data table/file utilization will be basically the same - look over the videos about 'records'.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top