Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Opening Balance, Credit and Debit in Trial Balance using SQL

(1) ShareShare
ReportReport
Posted on by 82
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
    1,190 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
    82 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
    1,190 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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Martin Dráb Profile Picture

Martin Dráb 601 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 416

#3
Adis Profile Picture

Adis 384 Super User 2025 Season 1

Product updates

Dynamics 365 release plans