Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Get sql value of query.

Posted on by Microsoft Employee

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Get sql value of query.

    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.

  • Suggested answer
    Rachit Profile Picture
    Rachit 4,015 User Group Leader on at
    Re: Get sql value of query.

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Get sql value of query.

    This returns something like : Query  object ca0fa50

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Get sql value of query.

    Use:

    info(query.toString());

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans