G
Guest
I have a table invtax that holds four records for each transaction number.
Each record lists the tax on a transaction for N (national), S (State), C
(County), I (local district). I have carefully examined this table to verify
there are no duplicate records.
I need to query this table to combine certain data into one record per
transaction number. Here is my query:
SELECT invtax.trans_id, invtax.order, Sum(invtax.taxrate) AS SumOftaxrate,
Max(IIf([taxtype]="S",[staxcode],"")) AS Scode,
Sum(IIf([taxtype]="S",[tax],0)) AS Stax,
Max(IIf([taxtype]="C",[ctaxcode],"")) AS Ccode,
Sum(IIf([taxtype]="C",[tax],0)) AS Ctax,
Max(IIf([taxtype]="I",[itaxcode],"")) AS Icode,
Sum(IIf([taxtype]="I",[tax],0)) AS Itax,
Max(IIf([taxtype]="N",[ntaxcode],"")) AS Ncode,
Sum(IIf([taxtype]="N",[tax],0)) AS Ntax, Max(invtax.taxable) AS Taxable,
Max(invtax.exempt) AS Exempt
FROM invtax
WHERE (((invtax.trans_id)>168000))
GROUP BY invtax.trans_id, invtax.order
ORDER BY invtax.trans_id, invtax.order;
The problem is that each time I run the query, I get a different number of
records and different records are duplicated with zero or null fields. In
5500 transactions I will get between 5500 and 5510 records.
Does anyone have an idea why I am getting these results?
Each record lists the tax on a transaction for N (national), S (State), C
(County), I (local district). I have carefully examined this table to verify
there are no duplicate records.
I need to query this table to combine certain data into one record per
transaction number. Here is my query:
SELECT invtax.trans_id, invtax.order, Sum(invtax.taxrate) AS SumOftaxrate,
Max(IIf([taxtype]="S",[staxcode],"")) AS Scode,
Sum(IIf([taxtype]="S",[tax],0)) AS Stax,
Max(IIf([taxtype]="C",[ctaxcode],"")) AS Ccode,
Sum(IIf([taxtype]="C",[tax],0)) AS Ctax,
Max(IIf([taxtype]="I",[itaxcode],"")) AS Icode,
Sum(IIf([taxtype]="I",[tax],0)) AS Itax,
Max(IIf([taxtype]="N",[ntaxcode],"")) AS Ncode,
Sum(IIf([taxtype]="N",[tax],0)) AS Ntax, Max(invtax.taxable) AS Taxable,
Max(invtax.exempt) AS Exempt
FROM invtax
WHERE (((invtax.trans_id)>168000))
GROUP BY invtax.trans_id, invtax.order
ORDER BY invtax.trans_id, invtax.order;
The problem is that each time I run the query, I get a different number of
records and different records are duplicated with zero or null fields. In
5500 transactions I will get between 5500 and 5510 records.
Does anyone have an idea why I am getting these results?