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
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
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
Hi D.K.S.,
I recommend reading this article on X++ data selection and manipulation.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156