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 :
Finance | Project Operations, Human Resources, ...
Answered

Converting SQL query to x++

(0) ShareShare
ReportReport
Posted on by
select sum(AccountingCurrencyAmount) as NETSALE, GeneralJournalAccountEntry.LedgerDimension,GeneralJournalAccountEntry.LedgerAccount from GeneralJournalAccountEntry
join GeneralJournalEntry on GeneralJournalAccountEntry.GeneralJournalEntry  =  GeneralJournalEntry.RecId
join MainAccount on GeneralJournalAccountEntry.MainAccount  =  MainAccount.RecId
join DimensionAttributeLevelValueView on GeneralJournalAccountEntry.LedgerDimension  =  DimensionAttributeLevelValueView.ValueCombinationRecId
join DimensionAttribute on DimensionAttributeLevelValueView.DimensionAttribute  =  DimensionAttribute.RecId
join FiscalCalendarPeriod on FiscalCalendarPeriod.RecId  =  GeneralJournalEntry.FiscalCalendarPeriod
where GeneralJournalEntry.AccountingDate >= '2019-10-01'  and  GeneralJournalEntry.AccountingDate <= '2019-10-31'
and GeneralJournalEntry.SubledgerVoucherDataAreaId  =  'apl'
and GeneralJournalAccountEntry.LedgerDimension  =  DimensionAttributeLevelValueView.ValueCombinationRecId
and DimensionAttribute.Name  =  'BusinessUnit'
and DimensionAttributeLevelValueView.DisplayValue  >=  '20311'  and  DimensionAttributeLevelValueView.DisplayValue  <=  '20311'
and FiscalCalendarPeriod.Type  =  '1'
and MainAccount.MainAccountId  =  '510001010'  or  MainAccount.MainAccountId  =  '510001020'
group by GeneralJournalAccountEntry.LedgerDimension, GeneralJournalAccountEntry.LedgerAccount 
Here is my Sql query and I have to implement the same logic in x++.
Thanks in advance.
I have the same question (0)
  • Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at

    Do you have any particular problem, such as that you don't know how to use replace SUM() or how to use date values?

    Or does it mean that you're not familiar with X++ at all and you need some of introduction?

  • Community Member Profile Picture
    on at

    I'am new to x++ and a bit help required and the code should be in loop and insert the data in a temp table.

    Thanks

  • Verified answer
    Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at

    You can either use the select statements integrated in X++, or you can use Query class (and related classes such as QueryBuildDataSource). The first option is more straigthforward (while the latter gives you more flexibility), therefore I suggest you start with that.

    You can find it explained (with examples) in AX documentation: Select statements.

    Regarding inserts, look at insert Table Method and insert_recordset.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 356

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans