General X++ Development

How do I see the SQL generated by an X++ select statement?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

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?

SSunny Vasty90 reputation · answered Aug 13, 2026

Yep. You can use generateonly along with getSQLStatement().

Here's a simple example:

X++
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:

X++
generateonly

generateonly 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:

X++
salesTable.getSQLStatement()