How to only show reports for those with a remaining balance











up vote
1
down vote

favorite












I've created a statement report that pulls from a query of a couple tables and groups them by ClientID and a couple sorts and each client has their statement on a separate page with their total owed.



The issue is that it shows clients that currently owe nothing and I only wish to print statements where their summed ChargeAmt is greater than zero. I cannot seem to be able to use Totals with a sum on the ChargeAmt since it just shows me the sum. Even when adding ChargeAmt again with the GroupBy option, it will continue to only show the summed value.



SELECT ChargeAccount.ClientID, Sale.SaleNo, Sale.SaleDate, Sale.LastName, ChargeAccount.ChargeAmt, Sale.FirstName, Sale.MI, Sale.StreetAddress, Sale.City, Sale.State, Sale.ZipCode, Sale.SaleTotal, ChargeAccount.ChDate
FROM ChargeAccount INNER JOIN
Sale
ON ChargeAccount.SaleNo = Sale.SaleNo
WHERE (((ChargeAccount.ChargeAmt)<>0))
ORDER BY Sale.LastName, ChargeAccount.ChargeAmt DESC;


Can I add a SUM function, maybe within a HAVING clause or something? I'm very new to this so I apologize if this is a simple matter.










share|improve this question




















  • 2




    Sample data and desired results would really help.
    – Gordon Linoff
    Nov 12 at 21:44










  • Sorry about that. Didn't think it would be necessary in this case. Thank you though.
    – Kyle
    Nov 13 at 16:41















up vote
1
down vote

favorite












I've created a statement report that pulls from a query of a couple tables and groups them by ClientID and a couple sorts and each client has their statement on a separate page with their total owed.



The issue is that it shows clients that currently owe nothing and I only wish to print statements where their summed ChargeAmt is greater than zero. I cannot seem to be able to use Totals with a sum on the ChargeAmt since it just shows me the sum. Even when adding ChargeAmt again with the GroupBy option, it will continue to only show the summed value.



SELECT ChargeAccount.ClientID, Sale.SaleNo, Sale.SaleDate, Sale.LastName, ChargeAccount.ChargeAmt, Sale.FirstName, Sale.MI, Sale.StreetAddress, Sale.City, Sale.State, Sale.ZipCode, Sale.SaleTotal, ChargeAccount.ChDate
FROM ChargeAccount INNER JOIN
Sale
ON ChargeAccount.SaleNo = Sale.SaleNo
WHERE (((ChargeAccount.ChargeAmt)<>0))
ORDER BY Sale.LastName, ChargeAccount.ChargeAmt DESC;


Can I add a SUM function, maybe within a HAVING clause or something? I'm very new to this so I apologize if this is a simple matter.










share|improve this question




















  • 2




    Sample data and desired results would really help.
    – Gordon Linoff
    Nov 12 at 21:44










  • Sorry about that. Didn't think it would be necessary in this case. Thank you though.
    – Kyle
    Nov 13 at 16:41













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I've created a statement report that pulls from a query of a couple tables and groups them by ClientID and a couple sorts and each client has their statement on a separate page with their total owed.



The issue is that it shows clients that currently owe nothing and I only wish to print statements where their summed ChargeAmt is greater than zero. I cannot seem to be able to use Totals with a sum on the ChargeAmt since it just shows me the sum. Even when adding ChargeAmt again with the GroupBy option, it will continue to only show the summed value.



SELECT ChargeAccount.ClientID, Sale.SaleNo, Sale.SaleDate, Sale.LastName, ChargeAccount.ChargeAmt, Sale.FirstName, Sale.MI, Sale.StreetAddress, Sale.City, Sale.State, Sale.ZipCode, Sale.SaleTotal, ChargeAccount.ChDate
FROM ChargeAccount INNER JOIN
Sale
ON ChargeAccount.SaleNo = Sale.SaleNo
WHERE (((ChargeAccount.ChargeAmt)<>0))
ORDER BY Sale.LastName, ChargeAccount.ChargeAmt DESC;


Can I add a SUM function, maybe within a HAVING clause or something? I'm very new to this so I apologize if this is a simple matter.










share|improve this question















I've created a statement report that pulls from a query of a couple tables and groups them by ClientID and a couple sorts and each client has their statement on a separate page with their total owed.



The issue is that it shows clients that currently owe nothing and I only wish to print statements where their summed ChargeAmt is greater than zero. I cannot seem to be able to use Totals with a sum on the ChargeAmt since it just shows me the sum. Even when adding ChargeAmt again with the GroupBy option, it will continue to only show the summed value.



SELECT ChargeAccount.ClientID, Sale.SaleNo, Sale.SaleDate, Sale.LastName, ChargeAccount.ChargeAmt, Sale.FirstName, Sale.MI, Sale.StreetAddress, Sale.City, Sale.State, Sale.ZipCode, Sale.SaleTotal, ChargeAccount.ChDate
FROM ChargeAccount INNER JOIN
Sale
ON ChargeAccount.SaleNo = Sale.SaleNo
WHERE (((ChargeAccount.ChargeAmt)<>0))
ORDER BY Sale.LastName, ChargeAccount.ChargeAmt DESC;


Can I add a SUM function, maybe within a HAVING clause or something? I'm very new to this so I apologize if this is a simple matter.







sql ms-access






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 21:41









Gordon Linoff

744k32285390




744k32285390










asked Nov 12 at 21:41









Kyle

83




83








  • 2




    Sample data and desired results would really help.
    – Gordon Linoff
    Nov 12 at 21:44










  • Sorry about that. Didn't think it would be necessary in this case. Thank you though.
    – Kyle
    Nov 13 at 16:41














  • 2




    Sample data and desired results would really help.
    – Gordon Linoff
    Nov 12 at 21:44










  • Sorry about that. Didn't think it would be necessary in this case. Thank you though.
    – Kyle
    Nov 13 at 16:41








2




2




Sample data and desired results would really help.
– Gordon Linoff
Nov 12 at 21:44




Sample data and desired results would really help.
– Gordon Linoff
Nov 12 at 21:44












Sorry about that. Didn't think it would be necessary in this case. Thank you though.
– Kyle
Nov 13 at 16:41




Sorry about that. Didn't think it would be necessary in this case. Thank you though.
– Kyle
Nov 13 at 16:41












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I would suggest joining your query to an aggregated subquery which returns the ClientID for those accounts for which the SUM of ChargeAmt is non-zero.



This removes the need for your WHERE clause as the selection criteria is implicit in the INNER JOIN:



SELECT 
ChargeAccount.ClientID,
Sale.SaleNo,
Sale.SaleDate,
Sale.LastName,
ChargeAccount.ChargeAmt,
Sale.FirstName,
Sale.MI,
Sale.StreetAddress,
Sale.City,
Sale.State,
Sale.ZipCode,
Sale.SaleTotal,
ChargeAccount.ChDate
FROM
(ChargeAccount INNER JOIN Sale ON ChargeAccount.SaleNo = Sale.SaleNo)
INNER JOIN
(
SELECT t.ClientID
FROM ChargeAccount t
GROUP BY t.ClientID
HAVING SUM(t.ChargeAmt) <> 0
) s ON ChargeAccount.ClientID = s.ClientID
ORDER BY
Sale.LastName, ChargeAccount.ChargeAmt DESC;





share|improve this answer

















  • 1




    This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
    – Kyle
    Nov 13 at 16:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270511%2fhow-to-only-show-reports-for-those-with-a-remaining-balance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










I would suggest joining your query to an aggregated subquery which returns the ClientID for those accounts for which the SUM of ChargeAmt is non-zero.



This removes the need for your WHERE clause as the selection criteria is implicit in the INNER JOIN:



SELECT 
ChargeAccount.ClientID,
Sale.SaleNo,
Sale.SaleDate,
Sale.LastName,
ChargeAccount.ChargeAmt,
Sale.FirstName,
Sale.MI,
Sale.StreetAddress,
Sale.City,
Sale.State,
Sale.ZipCode,
Sale.SaleTotal,
ChargeAccount.ChDate
FROM
(ChargeAccount INNER JOIN Sale ON ChargeAccount.SaleNo = Sale.SaleNo)
INNER JOIN
(
SELECT t.ClientID
FROM ChargeAccount t
GROUP BY t.ClientID
HAVING SUM(t.ChargeAmt) <> 0
) s ON ChargeAccount.ClientID = s.ClientID
ORDER BY
Sale.LastName, ChargeAccount.ChargeAmt DESC;





share|improve this answer

















  • 1




    This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
    – Kyle
    Nov 13 at 16:26















up vote
0
down vote



accepted










I would suggest joining your query to an aggregated subquery which returns the ClientID for those accounts for which the SUM of ChargeAmt is non-zero.



This removes the need for your WHERE clause as the selection criteria is implicit in the INNER JOIN:



SELECT 
ChargeAccount.ClientID,
Sale.SaleNo,
Sale.SaleDate,
Sale.LastName,
ChargeAccount.ChargeAmt,
Sale.FirstName,
Sale.MI,
Sale.StreetAddress,
Sale.City,
Sale.State,
Sale.ZipCode,
Sale.SaleTotal,
ChargeAccount.ChDate
FROM
(ChargeAccount INNER JOIN Sale ON ChargeAccount.SaleNo = Sale.SaleNo)
INNER JOIN
(
SELECT t.ClientID
FROM ChargeAccount t
GROUP BY t.ClientID
HAVING SUM(t.ChargeAmt) <> 0
) s ON ChargeAccount.ClientID = s.ClientID
ORDER BY
Sale.LastName, ChargeAccount.ChargeAmt DESC;





share|improve this answer

















  • 1




    This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
    – Kyle
    Nov 13 at 16:26













up vote
0
down vote



accepted







up vote
0
down vote



accepted






I would suggest joining your query to an aggregated subquery which returns the ClientID for those accounts for which the SUM of ChargeAmt is non-zero.



This removes the need for your WHERE clause as the selection criteria is implicit in the INNER JOIN:



SELECT 
ChargeAccount.ClientID,
Sale.SaleNo,
Sale.SaleDate,
Sale.LastName,
ChargeAccount.ChargeAmt,
Sale.FirstName,
Sale.MI,
Sale.StreetAddress,
Sale.City,
Sale.State,
Sale.ZipCode,
Sale.SaleTotal,
ChargeAccount.ChDate
FROM
(ChargeAccount INNER JOIN Sale ON ChargeAccount.SaleNo = Sale.SaleNo)
INNER JOIN
(
SELECT t.ClientID
FROM ChargeAccount t
GROUP BY t.ClientID
HAVING SUM(t.ChargeAmt) <> 0
) s ON ChargeAccount.ClientID = s.ClientID
ORDER BY
Sale.LastName, ChargeAccount.ChargeAmt DESC;





share|improve this answer












I would suggest joining your query to an aggregated subquery which returns the ClientID for those accounts for which the SUM of ChargeAmt is non-zero.



This removes the need for your WHERE clause as the selection criteria is implicit in the INNER JOIN:



SELECT 
ChargeAccount.ClientID,
Sale.SaleNo,
Sale.SaleDate,
Sale.LastName,
ChargeAccount.ChargeAmt,
Sale.FirstName,
Sale.MI,
Sale.StreetAddress,
Sale.City,
Sale.State,
Sale.ZipCode,
Sale.SaleTotal,
ChargeAccount.ChDate
FROM
(ChargeAccount INNER JOIN Sale ON ChargeAccount.SaleNo = Sale.SaleNo)
INNER JOIN
(
SELECT t.ClientID
FROM ChargeAccount t
GROUP BY t.ClientID
HAVING SUM(t.ChargeAmt) <> 0
) s ON ChargeAccount.ClientID = s.ClientID
ORDER BY
Sale.LastName, ChargeAccount.ChargeAmt DESC;






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 22:56









Lee Mac

2,77221036




2,77221036








  • 1




    This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
    – Kyle
    Nov 13 at 16:26














  • 1




    This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
    – Kyle
    Nov 13 at 16:26








1




1




This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
– Kyle
Nov 13 at 16:26




This did it! Thank you very much. I did leave the WHERE clause though because I had a dummy line in the table I couldn't get rid of due to a form issue I couldn't resolve. That clause was simply to leave out any ChargeAmt's of 0. Thanks again!
– Kyle
Nov 13 at 16:26


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270511%2fhow-to-only-show-reports-for-those-with-a-remaining-balance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?