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 = new Query(queryStr(WorkInstructionsQry));
qbd = query.addDataSource(TableNum(ProdTable));
qbr = qbd.addRange(FieldNum(ProdTable, ProdId));
qr = new QueryRun(query);
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.
You could use the trace parcer to get the exact statement all though it is a bit of a big tool for the job.
In this Blog article SQL is Extracted as s´Standard SQL Query
There is a X++ code showing how the who SQL is get out from starting at highest DS/Table
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?
Sorry for typos,
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.
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.
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.
you may try this to get standard SQL from Query object EcoResProductListPage
query = new Query(queryStr(EcoResProductListPage));
The logic i have shared that didn't return the correct result i have found some work around that will return exact T-SQL