Best way to copy filtered table data to temp table?

SteveSteve Member Posts: 81
We have to copy several "real" tables in temp for processing. Currently we are Navi 5.1 - SQL 2005.

We have several options, but I was looking for the most efficient and fastest method in Navision code.

1.
Table.SETRANGE(Field,Filter);
...
If Table.FINSET(FALSE,FALSE) THEN
REPEAT
TempTable.COPY(Table);
TempTable.INSERT;
UNTIL Table.NEXT=0;

2.
Table.SETRANGE(Field,Filter);
...
If Table.FINSET(FALSE,FALSE) THEN
REPEAT
TempTable.Field1 := Table.Field1;
....
TempTable.INSERT;
UNTIL Table.NEXT=0;

Any ideas would be appreciated. I guess these are the only 2 methods, but with the number of tables moving to temp I wanted to make sure I'm doing this the best method possible within Navision.

Thanks
Steve

Comments

  • jversusjjversusj Member Posts: 489
    edited 2009-01-06
    do you need all the fields of the record, or a limited subset? if you need all of them, i would think method 1 is the better bet. if you only need a few fields, you may be better off with the second.

    that's my thought - not knowing what you are ultimately trying to do.

    edit: :oops:

    yes yes. not COPY but temprec := rec.
    kind of fell into this...
  • kinekine Member Posts: 12,562
    All depends on if the temp table is same table as the source table, only defined as temporary. If yes, you can use only
    TempRec := Rec;
    TempRec.INSERT;
    

    If they are different, but the fields have same IDs, you can use
    TempRec.TRANSFERFIELDS(Rec);
    TempRec.INSERT;
    

    If they are totally different, you can use your second example. The first one have bigger overhead, because the COPY function copy filters and other things too...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.