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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Wanted to outerJoin 2 tables together using X++ Query Help

(0) ShareShare
ReportReport
Posted on by 40

// TableC1

Query query = new Query();

QueryBuildDataSource qbdsOne = query.addDataSource(tablenum(TableC1));

// TableC2

QueryBuildDataSource qbdsTableC2 = qbdsOne .addDataSource(tableNum(TableC2));

qbdsTableC2 .addLink(fieldNum(TableC1, B), fieldNum(TableC2, B));

// TableC3

QueryBuildDataSource qbdsTableC3 = qbdsTableC2 .addDataSource(tableNum(TableC3));

qbdsTableC3 .addLink(fieldNum(TableC2, B), fieldNum(qbdsTableC3 , B));

// TableA

QueryBuildDataSource qbds4 = qbdsTableC3 .addDataSource(tablenum(TableA  a));

qbds4 .joinMode(JoinMode::OuterJoin);

// TableC1

qbds4 .addLink(fieldNum(TableC1, C1), fieldNum(TableA  , field1), qbdsTableC1.name());

// TableC1

qbds4 .addLink(fieldNum(TableC1, C1), fieldNum(TableA  , field2), qbdsTableC1.name());

 

// TableC2

qbds4 .addLink(fieldNum(TableC2, C2), fieldNum(TableA  , field1), qbdsTableC2.name());pastedimage1609118812789v2.png

TableC1 is Okey but TableC2 is error

I have the same question (0)
  • Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at

    What's in the Message property of the exception and which line of code is throwing the exception?

    By the way, please don't prefix tags with #, do separate words with spaces and use "Microsoft Dynamics AX 2012" as the version for questions about AX 2012. Then you also don't need to tags like AX2012. And the category clearly is "Development / Customization / SDK", not "Supply Chain". I fixed it all for your this time.

  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Jjp,

    From your code, there are some errors.

    qbdsTableC1 did not declare, you are using qbdsOne, and in the TableC3 part, use addlink(), the parameter should be table name, and you provided qbdsTableC3.

    I degugged your code and have no error , get the statement as below, Whether it is what you want?:

    SELECT * FROM TableC1(TableC1_1) 
    JOIN * FROM TableC2(TableC2_1) ON TableC1.B = TableC2.B 
    JOIN * FROM TableC3(TableC3_1) ON TableC2.B = TableC3.B 
    OUTER JOIN * FROM TableA(TableA_1) ON TableC1.C1 = TableA.field1 AND TableC1.C1 = TableA.field2 AND TableC2.C2 = TableA.field1

    Your code:

    // TableC1
    Query query = new Query();
    QueryBuildDataSource qbdsTableC1 = query.addDataSource(tablenum(TableC1));
    
    // TableC2
    QueryBuildDataSource qbdsTableC2 = qbdsTableC1 .addDataSource(tableNum(TableC2));
    qbdsTableC2 .addLink(fieldNum(TableC1, B), fieldNum(TableC2, B));
    
    // TableC3
    QueryBuildDataSource qbdsTableC3 = qbdsTableC2 .addDataSource(tableNum(TableC3));
    qbdsTableC3 .addLink(fieldNum(TableC2, B), fieldNum(TableC3 ,B));
    
    // TableA
    QueryBuildDataSource qbds4 = qbdsTableC3 .addDataSource(tablenum(TableA));
    qbds4 .joinMode(JoinMode::OuterJoin);
    
    // TableC1
    qbds4 .addLink(fieldNum(TableC1, C1), fieldNum(TableA  , field1), qbdsTableC1.name());
    
    // TableC1
    qbds4 .addLink(fieldNum(TableC1, C1), fieldNum(TableA  , field2), qbdsTableC1.name());
    
    // TableC2
    qbds4 .addLink(fieldNum(TableC2, C2), fieldNum(TableA  , field1), qbdsTableC2.name());

  • hai ming Profile Picture
    20 on at

    是不是qbdsTableC1不存在呢?

  • Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at

    hai ming, please use English in this forum. Thank you.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    qbdsTableC3 .addLink(fieldNum(TableC2, B), fieldNum(qbdsTableC3 , B));

    to

    qbdsTableC3 .addLink(fieldNum(TableC2, B), fieldNum(TableC3, B));

    qbdsTableC3 --> TableC3 (Wang is saying You probaly dont have a table which is named qbdsTableC3)

    And You did began with qbdsOne but at somepoint used qbdsTableC1which is not declared before

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 356

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans