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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Query object: using a range on 2 datasources

(0) ShareShare
ReportReport
Posted on by 125

I am working on a form with a grid that needs to display records if a value on the grid's datasource does not match a value on another table. I'm adding the second table as a datasource to the main datasource but am having a difficult time finding an example of using a range to only select records where a field from both datasources don't match. An example sql statement is below.

select * from tablea tbla

 

inner

 

join tableb tblb on tblb.field1 = tbla.field1 and tblb.field2 <> tbla.field2

I'm assuming that adding a datasource for tableb to tablea and the using addlink statements to join the two is the correct path but haven't figured out the addrange part.

Thanks for the help, Jim

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    You are almost there, i made you an example with the salestable and salesLine.

    The query show all the salesTable where the deliveryname of the two tables is different.

       q = new Query();

       qbds1 = q.addDataSource(tablenum(SalesTable));

       qbds2 = qbds1.addDataSource(tablenum(SalesLine));

       qbds2.clearLinks();

       qbds2.addLink(fieldNum(SalesTable, SalesId), fieldnum(SalesLine, SalesId));

       qbr = qbds2.addRange(fieldnum(salesLine, RecId));

       qbr.value(strfmt("(%1.%3 != %2.%4)",

                        qbds1.name(),

                        qbds2.name(),

                        fieldstr(SalesTable, DeliveryName),

                        fieldstr(SalesLine, DeliveryName)));

    Hope this is where you are looking for.

    Kind Regards,

    Wouter Loosman

  • Jim Puehl Profile Picture
    125 on at

    Awesome, thanks Wouter, this did the trick! The part I was missing is:

    qbr.value(strfmt("(%1.%3 != %2.%4)",

                       qbds1.name(),

                       qbds2.name(),

                       fieldstr(SalesTable, DeliveryName),

                       fieldstr(SalesLine, DeliveryName)));

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans