Get underlying SQL query using getSQLStatement [Dynamics AX 2012]

Friends,

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)

{

    CustTable custTable;

    CustTrans custTrans;

    ;

   

    select generateonly firstOnly AccountNum, CustGroup

        from custTable join custTrans where custTrans.AccountNum == custTable.AccountNum;

    info(custTable.getSQLStatement());

 

}

Below is the SQL query.

 

image

Simple but very useful for developers for trouble shooting or to use it on reports.

 

Happy Dax6ng,

 

image

Advertisements

3 Responses to “Get underlying SQL query using getSQLStatement [Dynamics AX 2012]”

  1. Ivan Says:

    What about get sql statement for QueryRun?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: