Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Opening Balance, Credit and Debit in Trial Balance using SQL

Posted on by 20
Hi,
I'm recreating the trial balance that appears in AX 2012 in sql server. Rigth now, I have the closing balance but I want to get the opening balance, debit and credit. Is there a way that I can get those values? This is the query I have:
 
SELECT m.[PARTITION], m.MAINACCOUNTID, SUM(a.ACCOUNTINGCURRENCYAMOUNT) AS ACCOUNTINGCURRENCYAMOUNT
  FROM GENERALJOURNALACCOUNTENTRY a
  JOIN GENERALJOURNALENTRY e  ON e.[PARTITION] = a.[PARTITION] AND e.RECID = a.GENERALJOURNALENTRY
  JOIN MAINACCOUNT m          ON m.[PARTITION] = a.[PARTITION] AND m.RECID = a.MAINACCOUNT
  JOIN FISCALCALENDARPERIOD p ON p.[PARTITION] = e.[PARTITION] AND p.RECID = e.FISCALCALENDARPERIOD
  JOIN FISCALCALENDARYEAR FCY ON FCY.RECID = p.FISCALCALENDARYEAR
  WHERE p.[TYPE] = 1  -- 0=Opening,1=Operating,2=Closing
   AND m.MAINACCOUNTID = '111406'
   AND FCY.NAME = '2024'
  GROUP BY m.[PARTITION], m.MAINACCOUNTID
  ORDER BY m.[PARTITION], m.MAINACCOUNTID
 
  • Raj Borad Profile Picture
    Raj Borad 404 on at
    Opening Balance, Credit and Debit in Trial Balance using SQL
    Hi, 
    Can you please mark my reply as verified Answer.
     
    For opening balance, you can get the closing balance of the previous calendar year.
    Ex.: here you need to get the sum(AccountCurrency) for the year '2023'.
  • SP-22072258-0 Profile Picture
    SP-22072258-0 20 on at
    Opening Balance, Credit and Debit in Trial Balance using SQL
    Hi Raj,
    That worked fine, thank you!
  • Verified answer
    Raj Borad Profile Picture
    Raj Borad 404 on at
    Opening Balance, Credit and Debit in Trial Balance using SQL
    Hi,
    You can get the Debit and Credit with the use of IsCredit Field of GeneralJournalAccountEntry Table in your query.
     
    Thank you,
    Raj D Borad

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans