Why is the GROUP BY clause not working in my Query?

Dear All,
Below is the Query for a Summary Debtors Aged Analysis.
The GROUP BY clause does not seem to be working.
The Query returns all the unpaid invoices, instead of a single total row for each Customer.
If a Customer X has 10 unpaid invoices, 10 rows are displayed - one for each invoice.
I was expecting only 1 row for Customer X, 1 for Customer Y, etc.
This is what GROUP BY is supposed to do, but it is not doing its work.
What has gone wrong?
Thanks
Leon Lai
Here's my Query:
declare @taxdt datetime
set @taxdt
/*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
SELECT
CASE
             WHEN T0.Account = 1220101 THEN 'Prim Cust'
             WHEN T0.Account = 1220102 THEN 'Fgn Cust'
             WHEN T0.Account = 1220103 THEN 'Local Cust'
             WHEN T0.Account = 1220104 THEN 'Staff Loan' 
             WHEN T0.Account = 1220105 THEN 'Dep with TP'
             WHEN T0.Account = 1220106 THEN 'Adv to Cust'
             WHEN T0.Account = 1220108 THEN 'Sund Drs'
             ELSE 'Error ! ! !'
END AS 'Control A/c',
T1.CardCode AS 'BP Code',
T2.Notes2 AS 'BP Name',
SUM ((T0.Debit - T0.Credit)) AS 'Orig. Rs',       
SUM ((T0.BalDueDeb - T0.BalDueCred)) AS 'Bal. Rs',     
((SELECT SUM(T0.BalDueDeb) - Sum(T0.BalDueCred)
    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1))    
    AS '1 Mth Ago' 
/* Similarly for other age brackets*/
FROM JDT1 T0
INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
WHERE
T1.CardType = 'C'
and (Balance) != 0
and (T0.BalDueDeb - T0.BalDueCred) != 0
GROUP BY T0.Account, T1.CardCode, T2.Notes2, T0.TaxDate

Dear Neetu,
Thanks for your reply.
This Query is a modification of the Query you posted in SAP B1 SQL TIPS & TRICKS
http://wiki.sdn.sap.com/wiki/display/B1/SAPB1SQLB-FNDebtorsAgingReportbydate
So, maybe instead of referring to my Query, let's refer to yours. It may be easier for you to understand me.
Once I understand the problem, I can adapt your query to suit my requirements
So, let's start with a clean slate:
The Query you have posted is for a DETAILED Debtors Aging Report.
This lists all outstanding invoices, and ages them in the Age Brackets.
What I want is a SUMMARY Debtors Aging Report.
This will give the total amount owed by each Customer, and this amount is broken down in the Age Bracket Columns
There will be a single row listed for each customer, something like this:
Customer     Total Due     Current      1 Mth          2 Mth         3 Mth  etc
Alfred       500,000       300,000       200,000
Charles      800,000                     100,000       300,000       400,000
How can you modify your query to make it become a Summary Report (1 line for each customer even if he has many invoices)?
Thanks
Leon Lai
Here's your code
SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
     CASE  WHEN T0.TransType=13 THEN 'Invoice'
          WHEN T0.TransType=14 THEN 'Credit Note'
          WHEN T0.TransType=30 THEN 'Journal'
          WHEN T0.TransType=24 THEN 'Receipt'
          END AS 'Document Type',
     T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
WHERE (T0.MthDate IS NULL OR T0.MthDate > [%1]) AND T0.RefDate <= [%1] AND T1.CardType = 'C'
ORDER BY T1.CardCode, T0.DueDate, T0.Ref1

Similar Messages

  • Why does the address/status bar not work?

    After updating to 9.0.1, my status bar will not work, or my address bar. If I try to type in anything and press enter into the address bar, nothing happens. Also, I cannot press forward or back as they always remain grayed out. The only way I can get to a website is by pressing home, which is thankfully google. I have to google the url to go to it.
    Remembering now actually, I copied all the folders from the main firefox folder and pasted them into a new install of firefox (I had this problem actually before firefox updated). I was hoping that copying these folders would save my addons and etc. after I downloaded a new firefox and re-installed it. I put the folders back and firefox is still messed up :/
    I just want it to work more Q_Q

    That issue can be caused by an extension that isn't working properly.
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode

  • My iMessage and facetime is not working after updating to ios 7... My ipad works perfectly and it's the same apple id.  Any answers or reasons why on the iPhone 5 is not working???

    My iMessage and facetime is not working after updating to ios 7...
    Any answers on how to fix it?  I've tried to restart, restore connected to itunes, but nothing.

    ACTIVATING FACETIME AND IMESSAGES
    Activating Facetime and Imessages on your phone requires the ability to send SMS messages and depending upon where you are that might be an international SMS.  Check with your carrier to see if your plan supports sending of international SMS messages.  If you are having trouble activating Facetime or Imessages turn them both off on your device and reset the device (Hold down the Sleep/Wake button and the home button together until the apple logo appears (ignore the ON/OFF slider) then let both buttons go and wait for device to restart (no data will be lost)).  Wait for the device to restart and wait a minute and turn Facetime and imessage back on and wait for activation.  If that does not fix things read the following articles:
    http://support.apple.com/kb/TS4268
    http://support.apple.com/kb/ts3367

  • Why is the map in uae not working

    hi
    In UAE we face problems with maps. we can select one place but cannot go their (direction not working). Another this is Passbook doesn't work in UAE

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • HT201493 why is the notify me feature not work sometimes

    some times the notify me feature is avalable for some ppl and othere not?

    They have to update to ios6 for it to work all devices have to have ios6 to work with the new notify me to work.
    You can tell if the button on your device  is shaded out they need to update on there end.

  • Group By Clause not working in SQL Server CE Version 3.5.8080.0. Help needed

    SELECT Item_Type.Name AS Item_Type_Name,Category.Name AS Category_Name,UoM.UoM_Name AS Unit_Name,SUM(Invoice_Item.Quantity) AS Qty_Sold,SUM(Invoice_Item.Sold_Price) AS Sale_Price  
    FROM Invoice_Item 
    INNER JOIN Item_Type ON Invoice_Item.ItemType_ID = Item_Type.ID 
    INNER JOIN Category ON Item_Type.Category_ID = Category.ID 
    INNER JOIN UoM ON Item_Type.UoM_ID = UoM.ID  
    GROUP BY Item_Type.ID 
    Its giving following error.
    Unable to get data.In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions. [ Select clause = Item_Type,Name ]

    Hi, you have also group by
    Item_Type.Name,Category.Name,UoM.UoM_Name
    Questo post è fornito &quot;così com'è&quot;. Non conferisce garanzie o diritti di alcun tipo. Ricorda di usare la funzione &quot;segna come risposta&quot; per i post che ti hanno aiutato a risolvere il problema e &quot;deseleziona
    come risposta&quot; quando le risposte segnate non sono effettivamente utili. Questo è particolarmente utile per altri utenti che leggono il thread, alla ricerca di soluzioni a problemi similari. ENG: This posting is provided &quot;AS IS&quot;
    with no warranties, and confers no rights. Please remember to click &quot;Mark as Answer&quot; on the post that helps you, and to click &quot;Unmark as Answer&quot; if a marked post does not actually answer your question. Please Vote This As
    Helpful if it helps to solve your issue. This can be beneficial to other community members reading the thread.

  • Why is the Watch ESPN app not working?

    All I get is that it is unavailable

    Yep, same here...ESPN app on the Apple TV quit today May 26 for me.  It just says 'not available, try again later'.  Have not found the answer anywhere on the web.  So I have to pull it up on the iPad ESPN app and send it to the Apple TV via Airplay.  This works great, full screen picture just as sharp.  So, uh, I guess I don't care if they fix it.  Except I can't use the iPad for anything else while I am watching the tennis games in Paris this week.  If I had to blame someone, I would select the blamee du jour.  Vlad.  Vlad is responsible for everything bad, everywhere.

  • Why is the a:visited style not working?

    Hello.  I have created a horizontal menu and would like the a:visited text and background colors to be the reverse of a:link.  The a:link and the a:hover work well.  But when I make the a: visited color and background color different from a:link, all of the links text turn black and the background turns white for all of them.  The links were not cicked on.  But when a link was clicked on, a thin border of the text color appears around the box surrounding the link that was clicked on.  I would appreciate knowing how to correct this.  I have included the following styling link information that is in the head and body of the the html and css documents :
    html document:                                                                                css document:
    ul {                                                                                                     .navigation {
        list-style-type: none;                                                                           width:   960px;
        text-align: right;                                                                                   height:    50px;
        padding-top: 6px;                                                                               margin-top:  50px;
        padding-bottom: 6px;                                                                         font-size: 18px;
                                                                                                                     z-index: 5     
    li {
        display: inline;
    a:link {
        color:#FFF;
        text-decoration: none;
        background-color:#000;
        text-align: center;
        padding: 0px;
    a:visited {
        text-decoration: none;
        color: #000;
        background-color: #FFF;
    a:hover {
        text-decoration: none;
        color:#000;
        background-color:#FFF;
    a:active {
        text-decoration: none;
        color: #FFFFFF;
        background-color: #000;
    </head>
    <body>                   
    <div class="navigation">
        <ul>
            <li><a href="index.html" target="_self">HOME</a></li>
            <li><a href="digital.html" target="_self">DIGITAL</a></li>
            <li><a href="drawing.html" target="_self">DRAWING</a></li>
            <li><a href="painting.html" target="_self">PAINTING</a></li>
            <li><a href="about.html" target="_self">ABOUT</a></li></ul>
    </div>
    </body>
    Thank you.

    You have to clear your browser history/cache or all of the links you have visited in the past (while previewing) will show as the visited style which is a white background and black text.

  • Why is the letter p is not working on my iPhone 4s?

    Using the keyboard, the letter "p" does work when the iPhone is held in the vertical position.

    Does the area the p letter is located on work with touch when the keyboard is not there?

  • Why is the New Flash Player not working on Firefox?

    I have recently updated my Flash Player and since then the Videos are no longer running on Firefox..
    Is there something that I have done Wrong?
    What can be done about it?
    Thanks
    Manager Sales
    www.djewels.org

    Tools>Add-ons
    Make sure it's:
    1. Enabled
    2. Always activated

  • Why iPhone 6 Plus sound microphone not working, but in the case of sound recordings in conversation mode work?

    Why iPhone 6 Plus sound microphone not working, but in the case of sound recordings in conversation mode work?

    Sighhhh, wasted so much time yesterday and today going around Sony centre and then carphone warehouse. They told me to come back after Easter.
    I came home, banged the phone against the wall and it worked.
    Turned out that mic was working on loud speaker and when using headphones so I thought that the secondary mic is working and the main one (placed with the speakers) isn't. So I banged that part against the wall slightly (in plastic case to prevent scratches) then put the phone underwater, waited for it to dry and now it's working. Idk how well and if it's of perfect quality again but people can hear me well.

  • Why cant I add contacts on the iphone4? the mail contacts calendars button unders settings, the contacts button, the add a contacts button under message and the phone button will not work to add a contact.

    Why cant I add contacts on the iphone4? the mail contacts calendars button unders settings, the contacts button, the add a contacts button under message and the phone button will not work to add a contact.

    Have you attempted a restore?

  • My IPad cannot download live Tv from skygo. I have no problem with my lap top so I assume the broad band is okay. Can anybody suggest why the live streaming will not work on my iPad one.

    My IPad cannot download live Tv from skygo. I have no problem with my lap top so I assume the broad band is okay. Can anybody suggest why the live streaming will not work on my iPad .

    Are you using the Sky Go app to try and watch it ? If so are you logged in with your Sky account ?
    If you are using the app then you could try closing the app completely and see if it works when you re-open it : from the home screen (i.e. not with Sky Go 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Sky Go app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work then you could try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • How to delete multiple songs from iPhone 5S without losing form iTunes? The unchek function has not worked. Why?

    How to delete multiple songs from iPhone 5S without losing form iTunes? The unchek function has not worked. Why?

    Sorry I had to reply through your profile Gail from Maine, my PC has java issues. In any event, when I delete them directly from my device everything is perfect and cool. However, in the rare instance I want to add new music that I actually buy in stores (I know, quite the unique and old-fashioned idea...but hey Im an audiophile) once I upload the tunes, everytime I sync my library it re-adds everything that I spent hours deleting. In a perfect world, I thought I could maintain a massive iTunes Library, and add or delete (remove) songs from my iPhone to save both memory or keep my iPhone selections more current/apt to my musical "tastes" at that time. I know about the whole playlist thing, but thought there might be an easier way. ie - checking/un-checking the little box next to the song name, and then doing a sync. Again, everytime I do this however, whether everything is checked or un-checked it adds the entire library! So frustrating. Any suggestions. Thank you graiously in advance for your help.

  • Why is the new Safari (7) not letting sound be heard from Soundcloud widgets (players) on my website when the earlier Safari worked fine, and other browsers also work fine?

    Why is the new Safari (7) not letting sound be heard from Soundcloud widgets (players) on my website when the earlier Safari worked fine, and other browsers also work fine?

    Might be an incompatible extension or plugin ...
    Try troubleshooting Safari extensions and third party plugins.
    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test. If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.
    If it's not an extensions issue, try troubleshooting third party plug-ins.
    Back to Safari > Preferences. This time select the Security tab. Deselect:  Allow all other plug-ins. Quit and relaunch Safari to test.
    If that made a difference, instructions for troubleshooting plugins here.

Maybe you are looking for

  • Huge lack of functionality - Please write about what is lacking in Photos.

    Is it just me or are we missing functionality in Photos? Photos cannot be used professionally as it is currently  -  As I see it, the program is only 80% finished Please write about what is lacking in Photos. 1) Shared Albums, sort order. Optional so

  • Max number of chars in process message MSEL?

    Hi, what is the max number of characteristics can be used in process message category's MSEL table? Right now, I am using more than 99 characteristics and I get a short dump DYNPRO_FIELD_CONVERSION. Is it really limited to 99 characteristics and if i

  • How can I speed up FCPX

    To all you frustrated FCPX users, I am a wedding videographer, I made the transiton from final cut studio to FCPX and find it to be an excelent programme.  That is until I started to produce a 90 minute complex wedding video with 500+ clips, 10 track

  • Code should be enhanced until it is unicode enabled?

    Hi, I did a test of the unicode compatibility of the user-exits. And I get the following error: Part of function group SAPLXKAEP see LXKAEPTAP need to be enhanced. There is 1 marked program or include file, which are used together with original SAP c

  • HT4623 Change of Email Address

    Hi , Kindly advise me how to update my email address to my iphone from : ***** to ***** with immediate effect. Tks & Rgds Lisa Chye <E-mail Edited by Host>