Applying the SETCURRENTKEY twice

AndwianAndwian Member Posts: 627
Dear Experts,

I just want to ask you, whether these practice of applying the SETCURRENTKEY twice is a good practice?
SalesShptHeader.RESET;
SalesShptHeader.SETCURRENTKEY("Sell-to Customer No.","No."); --> 1st
SalesShptHeader.SETRANGE("Sell-to Customer No.","Sell-to Customer No.");

IF "Bill-to Customer No." <> '' THEN
  SalesShptHeader.SETCURRENTKEY("Bill-to Customer No."); --> 2nd
  SalesShptHeader.SETRANGE("Bill-to Customer No.","Bill-to Customer No.");
Thank you.
Regards,
Andwian

Answers

  • kinekine Member Posts: 12,562
    It is not "applying twice", it is just "change in decision" under some conditions... ;-) this code is good for Native DB, where the filtered fields should be covered by used key.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • AndwianAndwian Member Posts: 627
    kine wrote:
    It is not "applying twice", it is just "change in decision" under some conditions... ;-)
    Ah, yes... That's what I mean :mrgreen:
    kine wrote:
    this code is good for Native DB, where the filtered fields should be covered by used key.
    Is that good also for SQL Server DB?

    OR maybe it is better to add new key: "Sell-to Customer No.","Bill-to Customer No."?

    OR just like before, just change the key, at the time it is needed? :wink:

    Thank you Kamil.
    Regards,
    Andwian
  • kinekine Member Posts: 12,562
    I recommend to read more about the SQL optimization and the difference between keys and indexes. SQL will use index which will suite most to get the data in best way, but this decision could be sometime changed based on the required sort order (selected key in NAV).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • AndwianAndwian Member Posts: 627
    OK. Thank you anyway, Kamil! :D
    Regards,
    Andwian
Sign In or Register to comment.