General X++ Development
How do I see the SQL generated by an X++ select statement?
I have an X++ select statement and want to see the actual SQL that D365FO generates behind it.
Is there a way to get the generated SQL without actually running the query?
1 answer
Write an answerYep. You can use generateonly along with getSQLStatement().
Here's a simple example:
internal final class GetSqlStatement
{
public static void main(Args _args)
{
SalesTable salesTable;
select generateonly firstonly SalesId, CustAccount, SalesStatus
from salesTable
where salesTable.SalesStatus == SalesStatus::Backorder;
info(salesTable.getSQLStatement());
}
}The important part here is:
generateonlygenerateonly tells X++ to generate the SQL for the select statement without actually executing it.
Once the statement has been generated, you can get the SQL using:
salesTable.getSQLStatement()Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer