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.
sql ms-access
add a comment |
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.
sql ms-access
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
add a comment |
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.
sql ms-access
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
sql ms-access
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
add a comment |
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
add a comment |
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;
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
add a comment |
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;
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
add a comment |
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;
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
add a comment |
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;
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;
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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