web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    236,570 Most Valuable Professional on at
    RE: Converting SQL query to x++

    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
    RE: Converting SQL query to x++

    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
    236,570 Most Valuable Professional on at
    RE: Converting SQL query to x++

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,922

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,922

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 835 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans