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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to get Standard SQL out from Query Object in AOT?

(0) ShareShare
ReportReport
Posted on by 900

Hello,

I'm trting to get SQL out of Query Object made in AOT.

Tried this code BUT it only returns the first SQL clause not all ones combined together.

I think that dataSourceNo(1) <= numer one here restrictes getting all SQL code.

Any ideas, how to do it?

 

Query query;    

QueryBuildDataSource qbd;    

QueryBuildRange qbr;    

QueryRun qr;    

;

query = new Query(queryStr(WorkInstructionsQry));    

qbd = query.addDataSource(TableNum(ProdTable));    

qbr = qbd.addRange(FieldNum(ProdTable, ProdId));    

 qbr.value("PRD_00000062");    

 qr = new QueryRun(query);    

 info(qr.query().dataSourceNo(1).toString());

Br

Mike

 

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    RE: How to get Standard SQL out from Query Object in AOT?

    You created a query with two root datasources, but you call toString() only on the first one. There is no "query combined together", you simply have two queries. What you probably want is to get an existing datasource from the query and add ProdTable as its child, not as a root-level datasource. Another thing that you might be trying to do is UNION query.

  • Suggested answer
    Søren Rasmussen - Bredana Profile Picture
    817 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    You could use the trace parcer to get the exact statement all though it is a bit of a big tool for the job.

  • Mike Land Profile Picture
    900 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    Hello,

    In this Blog article SQL is Extracted as s´Standard SQL Query

    bmdax.blogspot.fi/.../getting-x-sql-statement-from-aot-query.html

    There is a X++ code showing how the who SQL is get out from starting at highest DS/Table

    element.query().dataSourceName(literalstr(ProdTable)).toString();

    I tried this code but what in my case comes is the SQL only for highest DS/table nothing below it...

    what can be wrong?

    Article also showed SQL that was extracted:

    SELECT * FROM ProdTable GROUP BY ProdTable.ProdId, ProdTable.InventRefType, ProdTable.InventRefId, ProdTable.Name, ProdTable.ItemId, ProdJournalTable.ProdId, InventDim.inventBatchId, InventDim.configId, InventDim.InventSizeId, InventDim.InventColorId WHERE ((ProdId = N'PO0800000403')) JOIN * FROM ProdJournalTable WHERE ProdTable.ProdId = ProdJournalTable.ProdId AND ((Posted = 1)) AND ((JournalType = 1)) JOIN JournalId, SUM(QtyGood) FROM ProdJournalProd WHERE ProdJournalTable.JournalId = ProdJournalProd.JournalId AND ProdJournalTable.JournalType = 1 AND ((NOT (QtyGood = 0))) JOIN * FROM InventDim WHERE ProdJournalProd.InventDimId = InventDim.inventDimId AND ((NOT (inventBatchId = ' ')))

    but when I put this code to SAL Management Studio it says: error near WHERE clause.

    Maybe those JOIN * FROM

    Can anyone explain what's going on?

    Best Regards,

    Mike

  • Mike Land Profile Picture
    900 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    Sorry for typos,

    Br

    Mike

  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    RE: How to get Standard SQL out from Query Object in AOT?

    If you don't see SQL for child datasource, change FetchMode to 1:1.

    The resulting text is SQL-like language, not T-SQL. For example, is uses EXISTS JOINs, that are translated to subqueries in T-SQL. If you want the real query processed by SQL Server, use tools working on DB level.

  • Mike Land Profile Picture
    900 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    Hello,

    This tools is behind of ParnerSource program.

    Okey, our Company is in it.

    But I couldn't get it working in AX 2009.

    I checked every details and enabled tracing in AX.

    But everytime this application tried to read the tracefile it crashed.

    Br

    Mike

  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    RE: How to get Standard SQL out from Query Object in AOT?

    I can't say what problem do you have with Trace Parser, but you can also use SQL Server Profiler. I actually prefer it is such situations.

  • Suggested answer
    Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    you may try this to get standard SQL from Query object EcoResProductListPage

    Query query;

    query = new Query(queryStr(EcoResProductListPage));

    info(query.dataSourceNo(1).toString());

  • Suggested answer
    Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to get Standard SQL out from Query Object in AOT?

    The logic i have shared that didn't return the  correct result i have found some work around that will return exact T-SQL

    www.daniellandi.com

  • Community Member Profile Picture
    on at
    RE: How to get Standard SQL out from Query Object in AOT?

    I want to write an extracted record to a new table that i created but dont know how to do it, can any one guide me

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
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans