Creating a function to copy data between 2 tables

rstolsrstols Member Posts: 28
edited 2009-08-26 in SQL General
I am new to development in Nav and need some help with developing the following function:

A new table was created which contains a few similar fields as an 'obsolete' table. I need to copy the data from the old table to the new table for all matching records for certain common fields. After it copied the data from the 'obsolete' table, it can delete those records in the 'obsolete' table.

Both tables contain 2 fields (store # and invoice #) which should be unique in both tables.

Any suggestions or ideas please?

Thanks
Rudy

Comments

  • garakgarak Member Posts: 3,263
    in C/AL (Navision) or in SQL (because u post this in the SQL General forum)?
    If NAV and both tables has the same structure (same fields with the same datatype) u can use the function "transferfields();"

    A NAV code can look like this:
    OldRec.reset;
    if OldRec.findset() then begin
      repeat
        NewRec.init;
        NewRec.transferfields(OldRec);
        NewRec.insert;
      until OldRec.next = 0;
    end;
    

    in SQL it is a simple insert into (fields) NewTable select(fields) from OldTable
    Do you make it right, it works too!
  • rstolsrstols Member Posts: 28
    The 2 tables don't have the same structure - only the common fields which needs to be transferred have the same datatype. Do you have any suggestions how to make that work?

    The other issue... is it also not required to first combine the 2 fields (store# + invoice#) in both tables temporarily in order to know which records need to be updated in the new table.

    Thanks for the help.
Sign In or Register to comment.