To get the underlying SQL query or statement from the X++ query, use getSQLStatement method. getSQLStatement is a new method that has been introduced in tables in AX 2012.
The X++ select has been extended with the generateonly command that instructs the underlying data access framework to generate the SQL query without actually executing it.
static void SR_getSQLStatement(Args _args)
select generateonly firstOnly AccountNum, CustGroup
from custTable join custTrans where custTrans.AccountNum == custTable.AccountNum;
Below is the SQL query.
Simple but very useful for developers for trouble shooting or to use it on reports.