Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculation queries - qry outputting multiple results from single inpt

Status
Not open for further replies.

Egglar

Technical User
Apr 4, 2002
88
GB
Apologies for the length of the post first .

This is actually spurring off another one of my threads. I cant find a solution to this problem, nor can I see what the problem is, its been bugging me for a bout 3 weeks on and off now, any help would be greatly appreciated.

I have three tables,

tblInvoice(InvoiceNo,InvoiceDate,Customer,MileageFee, CallOutFee,MOTFee)
tblParts(InvoiceNo,PartDescription,PartQTY,PartPrice)
tblLabour(InvoiceNo,LabourDescription,LabourCost)

InvoiceNo is Primary key in tblInvoice, and foreign key in the other two tables. A one to many relationship (because one invoice can have more than one part or labour cost)

I want to make a series of queries to calculate the sum of the Invoice overall, the process of this is:

qryPartsTotal
Grouping all the parts in tblParts that have the same InvoiceNo and summing them.
qryLabourTotal
Grouping all the parts in tblLabour that have the same InvoiceNo and summing them.
qrySubTotal
Adding the two outputs from the above two queries and also adding MileageFee and CallOutFee.
qryVATCalc
multiplies the SubTotal output by 0.175 to get the current VAT rate here in the UK.
qryInvoiceTotal
Adds the SubTotal and the VAT, and also adds the MOTFee(because this fee must not have VAT added to it). Outputs the final invoice total.

That’s basically what i want to do, and what I have done, using the above queries. But, after the grouping stages of the first 2 queries, if I use the outputs from them queries in another query, it tends to double up the outputs, and I end up with two of the same invoice number, hard to explain, must be harder to understand, ill attempt to show below. The test data im using is InvoiceNo 1 has £4.00 of parts and £3.00 of labour. InvoiceNo2 has £1.00 of parts and £1.00 of labour.
----------
qryPartsCalc
----------
PartsTotal InvoiceNo
£4.00 1
£1.00 2

----------
qryLabourCalc
----------
LabourTotal InvoiceNo
£3.00 1
£1.00 2

The results from the two above queries are correct.

-----------
qrySubTotal
-----------
InvoiceNo SubTotal PartsTotal LabourTotal
1 £2.00 £1.00 £1.00
1 £4.00 £1.00 £3.00
1 £5.00 £4.00 £1.00
1 £7.00 £4.00 £3.00
2 £2.00 £1.00 £1.00
2 £4.00 £1.00 £3.00
2 £5.00 £4.00 £1.00
2 £7.00 £4.00 £3.00

Please note that I have not put in the addition of the MileageFee or CallOutFee as not to make this more complicated than it needs to be at the moment.
This is the problem ive been getting, when you try to do anything with the outputted fields from the two base queries, it brings in the data as multiple records, of which I have now clue where they come from. There expected output is:

-----------
qrySubTotal
-----------
InvoiceNo SubTotal PartsTotal LabourTotal
1 £7.00 £4.00 £3.00
2 £2.00 £1.00 £1.00

To get round this, I joined qryPartsCalc and qryLabourCalc on the query design grid by InvoiceNo. This worked, and gave me the expected outputs. But, when I try to use the qrySubTotal in say qryVAT or qryInvoiceTotal; the outputs are split right up again, by the time I have got to InvoiceTotal and run the query, I end up with 1024 records being outputted, all with the InvoiceNo 1 or 2. Its ludicrous…

Any help you can give me will be gratefully received.

 
Hi,

I have read your note and think I solved a similar problem a while back. I can see how you are getting multiple rows. It think it is down to the reltionships between the queries.

The first thing to try will be to edit the relationship on the second query to be an outer join. If this does not work (which i suspect will be the case - you may get an error stating you need to specify which query is to run first) you could build a sequence of queries to build up the expected results.

Try changing the qryLabourTotal to include the qryPartsTotal and add the TotalParts with an outer join between the first query.

You can then build the result set up from there.

If this doesnt name sence cut your sql into a note and I will have a look.

Cheers
 
thats a little out of my league there, could you explain in a little bit more detail. what query do you suggest to outter join what?
 
Elliot,

I got your e-mail this morning, but didn't have a chance to respond to it. My webmail is down right now, so I'll have to wait a while longer. But I'm sure we can work something out.

I'll be in touch by sometime this evening (NY time).

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top