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

Merge Into like in Oracle to Foxpro 9

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
95
PH
Hi!

Is there a Merge Into in Foxpro 9 like what Oracle does?

From my previous thread in my table, I already have duplicate records that I wanted to delete the old one and retain the latest as-of-date. So now instead of inserting all records at once, I wanted to check if the new record has similar values to the old one before I update/replace or append it to the main table.

Update = with same rg+div+sta+empno but different as of date
Append = new records



Thank you!
 
YYou could try to do an UPDATE first with the WHERE conditions. If _TALLY = 0, then there was not a record found, and you could then do an INSERT. You would need to also include the current record date as part of the WHERE clause and use date > ldDate as the condition. Something like:

Code:
SELECT mytable
SCAN
[indent]SCATTER MEMO NAME loRecord
UPDATE mytable SET field1 = loRecord.field1, field2 = loRecord.field2, etc. ;
[indent]WHERE rg = loRecord.rg AND div = loRecord.div AND sta = loRecord.sta AND empno = loRecord.empno AND date > loRecord.date[/indent]
IF _TALLY = 0
[indent]INSERT INTO mytable (rg, div, sta, empno, date, etc) VALUES (loRecord.rg, loRecord.div, loRecord.sta, loRecord.empno, loRecord.date, loRecord.etc)[/indent]
ENDIF
[/indent]
ENDSCAN

Where etc refers to the additional fields of the table.

Greg
 
You could do something like this:

Code:
SELECT <the table you are updating>
LOCATE FOR <condition to indicate that the record is already in the table>
IF NOT FOUND()
  APPEND BLANK
ENDIF
REPLACE <the fields that need to be updated>

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top