This is a multi-part message in MIME format.
--Boundary_(ID_Cd2UnmHaBzpNsexySMHLDQ)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
I have a SELECT query that basically adds up my sales, removes credit
adjustments (eg. Returns) and gives the net figure.
This is the query:
SELECT (SELECT SUM(cli_tran_amount) FROM vetpmardet WHERE
cli_credit_adj_trans_no IN (SELECT sys_tran_number from vetpmardet WHERE
cli_tran_trans_date BETWEEN '2004-07-11' AND '2004-07-17' )) +
SUM(cli_tran_amount) AS amount FROM vetpmardet WHERE cli_tran_trans_date
BETWEEN '2004-07-11' AND '2004-07-17' AND sys_transaction_type LIKE 'C'
The subquery in there is necessary to link the credit back to the original
transaction. This query works well as far as I'm concerned.
Where I run into problems is when I try to break the report down by staff
codes. Unfortunately, my accounting s/w does not put a staff code with the
credit adjustment, but I do want to be able to see the net sales by staff
code. So I modify the query like this: (add one select column and a group by
clause)
SELECT dat_staff_code, (SELECT SUM(cli_tran_amount) FROM vetpmardet WHERE
cli_credit_adj_trans_no IN (SELECT sys_tran_number from vetpmardet WHERE
cli_tran_trans_date BETWEEN '2004-07-11' AND '2004-07-17' )) +
SUM(cli_tran_amount) AS amount FROM vetpmardet WHERE cli_tran_trans_date
BETWEEN '2004-07-11' AND '2004-07-17' AND sys_transaction_type LIKE 'C'
GROUP BY dat_staff_code
But this query will not produce a row for dat_staff_code when it's value is
null. It only produces grouped rows where dat_staff_code is not null, and
the sum of those rows does not equal the value of the single row returned in
the first query above. How do I get it to produce a row even when
dat_staff_code is null?
TIA
Caleb
--Boundary_(ID_Cd2UnmHaBzpNsexySMHLDQ)
Content-type: text/html; charset=us-ascii
Content-transfer-encoding: 7BIT
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:Arial;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.EmailStyle17
{font-family:Arial;
color:windowtext;}
[at] page Section1
{size:8.5in 11.0in;
margin:.5in .5in .5in .5in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-CA link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>I
have a SELECT query that basically adds up my sales, removes credit adjustments
(eg. Returns) and gives the net figure.</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>This
is the query:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>SELECT
(SELECT SUM(cli_tran_amount) FROM vetpmardet WHERE cli_credit_adj_trans_no IN
(SELECT sys_tran_number from vetpmardet WHERE cli_tran_trans_date BETWEEN
'2004-07-11' AND '2004-07-17' )) + SUM(cli_tran_amount) AS amount FROM vetpmardet
WHERE cli_tran_trans_date BETWEEN '2004-07-11' AND '2004-07-17' AND sys_transaction_type
LIKE 'C' </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>The subquery
in there is necessary to link the credit back to the original transaction. This
query works well as far as I’m concerned.</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>Where
I run into problems is when I try to break the report down by staff codes.
Unfortunately, my accounting s/w does not put a staff code with the credit
adjustment, but I do want to be able to see the net sales by staff code. So I
modify the query like this: (add one select column and a group by clause) </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>SELECT
dat_staff_code, (SELECT SUM(cli_tran_amount) FROM vetpmardet WHERE cli_credit_adj_trans_no
IN (SELECT sys_tran_number from vetpmardet WHERE cli_tran_trans_date BETWEEN
'2004-07-11' AND '2004-07-17' )) + SUM(cli_tran_amount) AS amount FROM vetpmardet
WHERE cli_tran_trans_date BETWEEN '2004-07-11' AND '2004-07-17' AND sys_transaction_type
LIKE 'C' GROUP BY dat_staff_code</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>But
this query will not produce a row for dat_staff_code when it’s value is
null. It only produces grouped rows where dat_staff_code is not null, and the sum
of those rows does not equal the value of the single row returned in the first
query above. How do I get it to produce a row even when dat_staff_code is null?</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>TIA</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>Caleb</span></font></p>
</div>
</body>
</html>
--Boundary_(ID_Cd2UnmHaBzpNsexySMHLDQ)--
