web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

SETRANGE example

(0) ShareShare
ReportReport
Posted on by

Hi, I have to solve this problem. 

I have one table, let's say T1 that contains ten random numbers. I have another table, called T2 that contains five random values. My goal is to insert into a third table let's say T3 all the values that are contained in T1 but not in T2. How can write the code to do that? I tried the following code but it doesn't work.  


IF T1.FINDSET THEN BEGIN

T1.SETRANGE(T1."No",T2."No");
  REPEAT
    T3.INIT;
    T3"No" := T1."No";
    T3.INSERT;
  UNTIL T1.NEXT = 0;

END;

I'm new at that, so I'm not an expert. Thank you

*This post is locked for comments

I have the same question (0)
  • MedInfoTech Profile Picture
    1,392 on at

    Please refer to this link

    msdn.microsoft.com/.../dd355219.aspx

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    T1.RESET

    IF T1.FINDSET THEN

    REPEAT

       T2.RESET;

       T2.SETRANGE("No.",T1."No.");

       IF NOT T2.FINDFIRST THEN BEGIN

          T3."no." := T1."No.";

          T3.INSERT;

       END;

     UNTIL T1.NEXT = 0;

    What you need is to loop through all the records from the T1 Table and in each loop find if that record is found in T2 or not if not found then insert into T3.

  • Suggested answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi Walidalam,

    IF T1.FINDSET THEN

     //Loop each T1 rows

     REPEAT

       //Check existing in T2

       T2.SETRANGE("No", T1."No");

       //Not found in T2 -> insert T3

       IF NOT T2.FINDSET THEN BEGIN

         T3.INIT;

         T3.TRANSFERFIELDS(T1);

         T3.INSERT;

       END;

     UNTIL (T1.NEXT = 0);

  • Suggested answer
    Binesh Profile Picture
    7,885 on at

    Hello,

    //>>Insert From T1 Table

    T1.RESET;
    IF T1.FINDSET THEN
      REPEAT
      IF NOT T2.GET(T1."No.") THEN BEGIN
        T3.INIT;
        T3."No." := T1."No.";
        T3.INSERT;
      END;
    UNTIL T1.NEXT = 0;

    //<<

    //>>Insert from T2 Table

    T2.RESET;
    IF T2.FINDSET THEN
      REPEAT
      IF NOT T3.GET(T2."No.") THEN BEGIN
        T3.INIT;
        T3."No." := T2."No.";
        T3.INSERT;
      END;
    UNTIL T2.NEXT = 0;

    //<<

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans