copying from one table to another table with existing records

Hi I'm a beginner in Navision and have a quick question, I want to copy records from OtherTempHeader table to rec but rec might have some records already... So far my code looks like this:


if not IsEmpty then begin
FindLast();
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end
else begin
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end;


It doesn't work. I would appreciate any tips, thank you :smile: !

Answers

  • vaprogvaprog Member Posts: 1,144
    edited 2019-09-25
    Please define "It doesn't work."
    Please use [code] quoting for your code, so indents are preserved. This makes it so much easyer to read, especially if you leave out optional BEGIN ... ENDs

    The FINDLAST does not have any effect regarding the inserts - this is a database which uses sorting according to the active key. Duplicates are detected by identical primary keys.
    For this reason the entire outer IF is not needed. the inner IFs are identical, You need one of them.

    Your code will work as long as you don't have any conflicts.
    If you have conflicts, it depends on what you need to do about them. Currently you get an error. (That might be perfectly good behavior.)
    If you need to ignore the new duplicate records, try
    IF INSERT THEN;
    
    If you need to overwrite duplicate records try
    IF NOT INSERT THEN
      MODIFY;
    
Sign In or Register to comment.