web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get sql value of query.

(0) ShareShare
ReportReport
Posted on by

Hello.

How can I get the sql string value from a Query object? (AX 2009).

(The select statement).

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Use:

    info(query.toString());

  • Community Member Profile Picture
    on at

    This returns something like : Query  object ca0fa50

  • Suggested answer
    Rachit Profile Picture
    4,015 User Group Leader on at

    It is stored in QueryBuildDataSource object of the query. So u have to use toString() function of queryBuildDataSource.

    Try to run this simple job:

       query query;

       queryBuildDataSource    qbds;

       ;

       query = new query();

       qbds = query.addDataSource(tableNum(CustGroup));

       info(qbds.toString());

    U can also access this directly from query object using the dataSource functions for e.g:

    info(this.query().dataSourceNo(1).toString());

    Thanks,

    Rachit Garg

  • Suggested answer
    Community Member Profile Picture
    on at

    If you are building an x++ query from scratch, info(query.toString()); would work.  From a form you use:  info(xxxx_DS.query().dataSourceNo(1).toString());

    A full breakdown can be found on this blog:  bmdax.blogspot.com/.../getting-x-sql-statement-from-aot-query.html

    *Remember that this returns an x++ query and not direct SQL.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans