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 AX (Archived)

Inherited Table EcoResDistinctProduct contains more data than expected

(0) ShareShare
ReportReport
Posted on by 35

From what I know, table EcoResProduct is a base table, table EcoResProductMaster (TableId = 3267) contains products which are product masters, EcoResDistinctProductVariant (TableID=3266) contains product variants, and EcoResDistinctProduct (TableId=3265) contains products which are not product masters and product variants.

So, I tried to use the following code (SQL - sent to SQL server, as well as X++) to check:

1. EcoResDistinctProduct:

SQL:

SELECT *  --> 9643 rows
FROM EcoResProduct
WHERE InstanceRelationType = 3265

X++:

int recCount = 0;

while select * from EcoResDistinctProduct

{

    recCount ++; //-->12570 rows

}

-----------

2. EcoResProductMaster:

SQL:

SELECT *  //--> 424 rows
FROM EcoResProduct
WHERE InstanceRelationType = 3267

X++:

int recCount = 0;

while select * from EcoResProductMaster

{

    recCount ++; //-->424 rows

}

---------------

3. EcoResDistinctProductVariant:

SQL:

SELECT *  //-->2927 rows
FROM EcoResProduct
WHERE InstanceRelationType = 3266

X++:

int recCount = 0;

while select * from EcoResDistinctProductVariant

{

    recCount ++; // --> 2927 rows

}

I compared the number of records from 2 commands for each case above and found out that the case #1 has an unexpected result.

The numbers of records in case #1 are different: the X++ statement (run on AOS) returns more records than SQL statement (sent directly to SQL server).

I am not sure why, please give me some hint.

Thanks,

Rocky

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Your SQL select statement has different condition (InstanceRelationType) than your x++ statement.

    Also please note that you can get count of records without iterating through them:

    int recCount = 0;
    
    select count(RecId)* from EcoResProductMaster;
    recCount = EcoResProductMaster.RecId;
    


  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Rocky,

    Actually, you can use the next statement to do a count using x++ which is much faster:

    EcoResDistinctProduct distinctProduct
    int recCount;
    
    select count(RecId) from distinctProduct
    
    recCount = distinctProduct.RecId;
    


    If you have a difference, you can actually export the data from SQL and also the EcoResDistinctProduct table from the table viewer in AX and compare them to find out what is actually different.

  • RockyLee Profile Picture
    35 on at

    In which case #, you think that the SQL condition is wrong,
    André Arnaud de Calavon?

  • RockyLee Profile Picture
    35 on at

    From the test result, it looks line X++ table EcoResDistinctProduct also contains data from X++ table EcoResDistinctProductVariant.

  • Verified answer
    RockyLee Profile Picture
    35 on at

    The issue with case #1:  the X++ select statement ...select * from EcoResDistinctProduct... returns more data than expected (12570 rows instead of 9643 rows).

    I use this code to investigate a bit further:

    while
    select InstanceRelationType, count(RecId)
    from ecoResDistinctProduct
    group by ecoResDistinctProduct.InstanceRelationType
    {
        info(strFmt("InstanceRelationType=%1 - RowsCount=%2",

                           ecoResDistinctProduct.InstanceRelationType,

                           ecoResDistinctProduct.RecId));
    }

    InfoLog shows the result messages:

    InstanceRelationType=3265 - RowsCount=9643
    InstanceRelationType=3266 - RowsCount=2927

    So, the X++ select statement of the case #1, also includes data from table EcoResDistinctProductVariant. This is what I don't expect. Not sure this issue is a AX 2012's bug or something in the table setting was setup wrongly.

    To work around this issue, I have to use the following code:

    select *

    from ecoResDistinctProduct

    where ecoResDistinctProduct.InstanceRelationType == 3265

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans