Skip to Content
author's profile photo Former Member
Former Member

Query to get G/L accounts even with the Zero transactions

Dear experts,

i have tried a query as below

SELECT T0.[AcctCode], T0.[AcctName], T0.[CurrTotal] AS 'Bank Balance', sum(T1.[Debit]) as 'Payment', sum(T1.[Credit]) as 'Collection' FROM OACT T0 LEFT OUTER

JOIN JDT1 T1 ON T0.AcctCode = T1.Account WHERE T0.[AcctCode] in ('162016','162010','162011','162002','162003','161010') AND T1.RefDate BETWEEN '[%0]' AND '[%1]'

GROUP BY T0.[AcctCode], T0.[AcctName], T0.[CurrTotal]

My requirement is

I have given 5 G/L accounts in where condition. I am getting the report only the account have debit or credit transaction.

whereas i want account in report even if it has "0" as transaction within that period.

Thanks in advance,

dwarak

Edited by: Dwarakanath.P on Nov 28, 2011 2:51 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Nov 28, 2011 at 02:00 PM

    hi Dwarakanath

    try this

    SELECT isnull(T0.AcctCode,0), T0.AcctName, isnull(T0.CurrTotal,0) AS 'Bank Balance',isnull(sum(T1.Debit),0) as 'Payment', isnull(sum(T1.Credit),0) as 'Collection' FROM OACT T0 LEFT OUTER
    JOIN JDT1 T1 ON T0.AcctCode = T1.Account WHERE T0.AcctCode in ('162016','162010','162011','162002','162003','161010') AND T1.RefDate BETWEEN '%0' AND '%1'
    GROUP BY T0.AcctCode, T0.AcctName, T0.CurrTotal

    Edited by: Fasolis Vasilios on Nov 28, 2011 3:01 PM

    Add a comment
    10|10000 characters needed characters exceeded

    • try this please

      SELECT 
      isnull(T0.AcctCode,0), T0.AcctName, (case when T0.CurrTotal!= ' ' then t0.currtotal else 0 end) 
       FROM OACT T0 LEFT OUTER
      JOIN JDT1 T1 ON T0.AcctCode = T1.Account WHERE T0.AcctCode in ('162016','162010','162011','162002','162003','161010') AND T1.RefDate ='2011-11-05'
      GROUP BY T0.AcctCode, T0.AcctName, T0.CurrTotal

  • Posted on Nov 29, 2011 at 10:23 AM

    Hi,

    Check this if it works for you :

    SELECT T0.AcctCode, T0.AcctName, CASE WHEN T0.CurrTotal != 0 THEN t0.Currtotal ELSE 0 END AS 'Bank Balance', 
    isnull(sum(T1.Debit),0) as 'Payment', isnull(sum(T1.Credit),0) as 'Collection' 
    FROM OACT T0 LEFT OUTER
    JOIN JDT1 T1 ON T0.AcctCode = T1.Account 
    WHERE T0.AcctCode in ('162016','162010','162011','162002','162003','161010')  
    AND T1.RefDate BETWEEN '2009.01.01' AND '2011.12.31'
    GROUP BY T0.AcctCode, T0.AcctName, T0.CurrTotal
    

    Kind Regards,

    Jitin

    SAP Business One Forum Team

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 29, 2011 at 06:54 PM

    Hi Dwarak,

    Try:

    SELECT T0.AcctCode, T0.AcctName, T0.CurrTotal AS 'Bank Balance', sum(IsNull(T1.Debit,0)) as 'Payment', sum(IsNull(T1.Credit,0)) as 'Collection'

    FROM OACT T0

    LEFT JOIN JDT1 T1 ON T0.AcctCode = T1.Account AND T1.RefDate BETWEEN '[%0\]' AND '[%1\]'

    WHERE T0.AcctCode in ('162016','162010','162011','162002','162003','161010')

    GROUP BY T0.AcctCode, T0.AcctName, T0.CurrTotal

    Thanks,

    Gordon

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Try:

      SELECT T0.AcctCode, T0.AcctName, sum(IsNull(T1.Debit,0))-sum(IsNull(T1.Credit,0)) AS 'Bank Balance', sum(IsNull(T1.Debit,0)) as 'Payment', sum(IsNull(T1.Credit,0)) as 'Collection'

      FROM OACT T0

      LEFT JOIN JDT1 T1 ON T0.AcctCode = T1.Account AND T1.RefDate BETWEEN '[%0\]' AND '[%1\]'

      WHERE T0.AcctCode in ('162016','162010','162011','162002','162003','161010')

      GROUP BY T0.AcctCode, T0.AcctName, T0.CurrTotal

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.