Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Opening Balance, Credit and Debit in Trial Balance using SQL

(1) ShareShare
ReportReport
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 494 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 494 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans