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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Data What's the best way?

Status
Not open for further replies.

LimitedTech

Technical User
Aug 4, 2008
71
US
I have two tables. They both contain the field "InvoiceNumber". Table A has 1 record for "InvoiceNumber". Table B has multiple records for "InvoiceNumber". Both also have an "Amount" field and a "Quantity" field. I am trying to compare the "Amount" and "Quantity" fields for the matching records from each Table. Obviously the data from Table B will have multiple records and will need to be summed before they are compared.
I will also need to verify table B has at least one matching record for each record in table A.

Any idea on the best way to accomplish this?
 
Do you have a relation establieshed between Table A (parent) and Table B (child) based on PK-FK (one-to-many) of InvoiceNumbe?

And, if a records in Table B has 10, 12, and 15 for Quantity, do you have to have Quantity in Table A of the sum of 10, 12, and 15?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Yes, I have a relationship established.
Quantity (one record) in Table A should match the sum of quantity (multiple records) in table B.
We have a customer that pays our invoices on separate line items. we only use one line to invoice. I am working on a method to reconcile the two.
 
So it looks to me you are looking for Parent records (Table A) that do not have children records (Table B)

In Oracle I would try:[tt]
Select InvoiceNumber From TableB
MINUS
Select InvoiceNumber From TableA[/tt]

I hope you can do the same in Access

or (this will work in Access)
[tt]
Select InvoiceNumber From TableA
Where InvoiceNumber NOT IN (
Select InvoiceNumber From TableB)
[/tt]

But – in my opinion, it is very bad idea to have calculated fields in your DB.
By ‘calculated’ I mean: you have 10-12-15 in one table, and a Sum of it in another. Why….?


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top