Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

x++ Group by slows down execution

(0) ShareShare
ReportReport
Posted on by

Hey guys!

I created an SQL Statement in x++:

select ItemId, DataAreaId, sum(Qty)
    from reqTrans join reqPlanVersion
                  join inventTable
                  join Name from ecoResProductTranslation
                  join InventLocationId from inventDim
                  join InventLocationId from inventDim
    group by reqTrans.ItemId, reqTrans.dataAreaId, ecoResProductTranslation.Name, inventDim.InventLocationId
    where reqTrans.PlanVersion == reqPlanVersion.RecId
    && (reqPlanVersion.ReqPlanId == 'Statisch' || reqPlanVersion.ReqPlanId == 'Static')
    && reqPlanVersion.ReqPlanDataAreaId == reqTrans.dataAreaId
    && reqPlanVersion.Partition == reqTrans.Partition
    && reqTrans.ItemId == inventTable.ItemId
    && !(inventTable.ItemId like '300.___.___')
    && !(inventTable.ItemId like '900.___.___')
    && inventTable.PmfProductType == 0
    && inventTable.dataAreaId == reqTrans.dataAreaId
    && inventTable.Partition == reqTrans.Partition
    && inventTable.Product == ecoResProductTranslation.Product
    && inventTable.Partition == ecoResProductTranslation.Partition
    && reqTrans.CovInventDimId == inventDim.inventDimId
    && reqTrans.dataAreaId == inventDim.dataAreaId
    && reqTrans.Partition == inventDim.Partition
    && reqTrans.RefType == 10 || reqTrans.RefType == 12 || reqTrans.RefType == 14 || reqTrans.RefType == 21 || reqTrans.RefType == 32;


This Statement can not execute in an finit time. I tried it and after 2 Hours it was still working. 

Without the "Group by", the whole Thing only lasts for 10 seconds. Whats the Problem here?

If I execute the whole Thing, with the Group by, on the SQL Server itself in the MS Management Studio, it takes only 1 second.

There cannot be such a big difference in time.

I hope that someone can help me with my Problem.

THANKS!

*This post is locked for comments

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: x++ Group by slows down execution

    Hi loijoc08,

    You can use getSQLStatement() method to get actual SQL statement  AX generates and see what is wrong there, please refer for example community.dynamics.com/.../get-from-x-query-to-get-sql-query-using-getsqlstatement-for-trouble-shooting-dynamics-ax-2012

    But this query looks really strange,  why do you need 2 joins identical joins?

    join InventLocationId from inventDim
    
    join InventLocationId from inventDim


    Here you forget to put brackets

     && reqTrans.RefType == 10 || reqTrans.RefType == 12 || reqTrans.RefType == 14 || reqTrans.RefType == 21 || reqTrans.RefType == 32;


    Also why do you group by dataareaid if you don't use crosscopmany ? 

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans