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)

CTE

(0) ShareShare
ReportReport
Posted on by

are the CTE available in ax? i'm trying to optimize some queries and given a quick check i've noticed that i can group those in which only one condition is different, but i cant find any informatión about CTE on ax. here and example of what im trying to do

current Queries:

query1:

select sum(qty)
from t1
where "conditions" exists join t2
where t1.Id == t2.Id
&& t2.conditionfield like "CHANGING CONDITION 1*" exists join inventDim
where "More conditions";

query2:

select sum(qty)
from t1
where "conditions" exists join t2
where t1.Id == t2.Id
&& t2.conditionfield like "CHANGING CONDITION 2*" exists join inventDim
where "More conditions";

Using cte:

WITH info
AS
(
SELECT CASE
                    WHEN t2.conditionfield like 'changing condition 1%' THEN CC1 '
                    WHEN t2.conditionfield like 'changing condition 2%' THEN 'CC2'
             END VARIABLE,SUM(QTY) SumResult

from t1 join t2
on t1.Id = t2.Id join inventDim
on t1Id = t3.Id
where conditions
Group by CASE
                    WHEN t2.conditionfield like 'changing condition 1%' THEN CC1 '
                    WHEN t2.conditionfield like 'changing condition 2%' THEN 'CC2'
               END
)

so I only make one call to the database with various results instead of many calls with one result.

well all least this was my first thought but as i said, cant find anything about CTE in AX, can this be done? 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi luis torres,

    Simple answer is - No. You have to do 2 queries. 

  • Community Member Profile Picture
    on at

    that's sad, well thank you ievgen

  • Mea_ Profile Picture
    60,284 on at

    Usually when you optimize queries you look at query plan ,search for missing indexes, etc.  Have you checked that query generated from AX is actually slower than query you want to have ?

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