Skip to main content

Notifications

Dynamics 365 Community / Forums / Commerce forum / how to use .AX and .DB...
Commerce forum

how to use .AX and .DBO database in X++ D365.

Posted on by 1,010

Hi Experts,

I want to use SQL query from two different database .AX and .Dbo database in X++. The queries are Select * from ax.RetailTransactionSalesTrans and Select * from Dbo.RetailTransactionSalesTrans in SQL. I need to get data from these two queries in X++.

How to write these queries in X++ in D365F ? Right now in X++, "Select * from RetailTransactionSalesTrans" query is taking data from Dbo.RetailTransactionSalesTrans table.

Regards,

DKS

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to use .AX and .DBO database in X++ D365.

    Hi D.K.S.

    After operating according to link above, I confirm it works

    public static void main(Args _args)

        {  

            Connection      connection;

            Statement       statement;

            str             query;

            Resultset       resultSet;

           

     

            // create connection object

            connection = new Connection();

     

            // create statement

            statement = connection.createStatement();

     

            // Set the SQL statement

            query = 'select distinct taxgroup from ax.RetailTransactionSalesTrans union select distinct taxgroup from dbo.RetailTransactionSalesTrans';

     

            // assert SQL statement execute permission

            new SqlStatementExecutePermission(query).assert();

     

            // when the query returns result,

            // loop all results for processing

            //BP Deviation documented

            resultSet = statement.executeQuery(query);

     

            while(resultSet.next())

            {

                // do something with the result

                info(resultSet.getString(1));

            }

     

            // limit the scope of the assert call

            CodeAccessPermission::revertAssert();

    }

    Best Regards

    Tom Cai

  • Suggested answer
    Jayaprakash Reddy Profile Picture
    Jayaprakash Reddy 270 on at
    RE: how to use .AX and .DBO database in X++ D365.

    Hi,

    You can follow below blog to achieve your results. its shows that how to execute direct SQL statement from AX. in SQL query statement, just type like"ax.RetailTransactionSalesTrans", so you get channel database transactions

    [Executing SQL directly from X++]

    [Executing direct SQL statements to different databases]

    Hope this helps!

    Thanks/Jayaprakash 

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: how to use .AX and .DBO database in X++ D365.

    Hi D.K.S.,

    I recommend reading this article on X++ data selection and manipulation.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans