dbTalk Databases Forums  

Extracting data

comp.databases.ms-access comp.databases.ms-access


Discuss Extracting data in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default Extracting data - 06-01-2010 , 01:28 PM






Here is the result of a query. This query was created using 2 temporary
tables which hold every combined total of a number of payments ( I have
allowed up to 10) and every combined total of charges for spaces

The raw data is
Payments £79 and £147
Space Charges £26.50, 52.50 and £147


MemberID TotPayments TotPaymentIDs PID1 PID2 PID3 PID4 PID5 PID6 PID7 PID8 PID9 PID10 TotSpaceIDs SID1 SID2 SID3 SID4
969 £147.00 1 3267 1 230

969 £147.00 1 3267 1 230

969 £147.00 1 3267 1 230

969 £79.00 1 2850 2 397 94

969 £226.00 2 2850 3267 3 397 94 230

969 £226.00 2 2850 3267 3 397 94 230

969 £226.00 2 2850 3267 3 397 94 230

PID are Payment IDs and SID are Spaces being paid for.
Now it is obvious that PaymentID 3267 pays for SpaceID 230 and PaymentID 2850
pays for spaces 307 and 94

The SQL is SELECT TempPayments.*, TempStorageFees.TotSpaceIDs,
TempStorageFees.SID1, TempStorageFees.SID2, TempStorageFees.SID3,
TempStorageFees.SID4, TempStorageFees.SID5, TempStorageFees.SID6,
TempStorageFees.SID7, TempStorageFees.SID8, TempStorageFees.SID9,
TempStorageFees.SID10 FROM TempPayments INNER JOIN TempStorageFees ON
(TempPayments.MemberID = TempStorageFees.MemberID) AND
(TempPayments.TotPayments = TempStorageFees.TotStorageFeesPaid) ORDER BY
TempStorageFees.TotSpaceIDs, TempPayments.TotPaymentIDs;

Any ideas on how to extract this information to get the result above so that
I can write the appropriate transaction?

Reply With Quote
  #2  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: Extracting data - 06-02-2010 , 05:20 AM






Your table is badly denormalized. Correct the design so that you don't have
repeating groups and you should find the query much easier to construct.

You've got a classic many-to-many relationship: one payment can apply to
multiple spaces, one space can be paid by multiple payments. That implies
you need three tables: one for payments, one for spaces, and one to resolve
that many-to-many relationship.

If the concept of database normalization isn't familiar to you, take a look
at some of the resources Jeff Conrad lists at
http://www.accessmvp.com/JConrad/acc...abaseDesign101

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
Here is the result of a query. This query was created using 2 temporary
tables which hold every combined total of a number of payments ( I have
allowed up to 10) and every combined total of charges for spaces

The raw data is
Payments £79 and £147
Space Charges £26.50, 52.50 and £147


MemberID TotPayments TotPaymentIDs PID1 PID2 PID3 PID4 PID5 PID6 PID7 PID8
PID9 PID10 TotSpaceIDs SID1 SID2 SID3 SID4
969 £147.00 1 3267 1 230

969 £147.00 1 3267 1 230

969 £147.00 1 3267 1 230

969 £79.00 1 2850 2 397 94

969 £226.00 2 2850 3267 3 397 94 230

969 £226.00 2 2850 3267 3 397 94 230

969 £226.00 2 2850 3267 3 397 94 230

PID are Payment IDs and SID are Spaces being paid for.
Now it is obvious that PaymentID 3267 pays for SpaceID 230 and PaymentID
2850
pays for spaces 307 and 94

The SQL is SELECT TempPayments.*, TempStorageFees.TotSpaceIDs,
TempStorageFees.SID1, TempStorageFees.SID2, TempStorageFees.SID3,
TempStorageFees.SID4, TempStorageFees.SID5, TempStorageFees.SID6,
TempStorageFees.SID7, TempStorageFees.SID8, TempStorageFees.SID9,
TempStorageFees.SID10 FROM TempPayments INNER JOIN TempStorageFees ON
(TempPayments.MemberID = TempStorageFees.MemberID) AND
(TempPayments.TotPayments = TempStorageFees.TotStorageFeesPaid) ORDER BY
TempStorageFees.TotSpaceIDs, TempPayments.TotPaymentIDs;

Any ideas on how to extract this information to get the result above so
that
I can write the appropriate transaction?

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Extracting data - 06-02-2010 , 03:54 PM



On 02/06/2010 11:20:15, "Douglas J. Steele" wrote:
Quote:
Your table is badly denormalized. Correct the design so that you don't
have repeating groups and you should find the query much easier to
construct.

You've got a classic many-to-many relationship: one payment can apply to
multiple spaces, one space can be paid by multiple payments. That implies
you need three tables: one for payments, one for spaces, and one to
resolve that many-to-many relationship.

If the concept of database normalization isn't familiar to you, take a
look at some of the resources Jeff Conrad lists at
http://www.accessmvp.com/JConrad/acc...abaseDesign101

Thanks for coming back Douglas.

I have the thre tables that you mentioned. I know what spaces a person has
and their cost. I know the payments received. What I am tring to do is deduce
from the payment which spaces he is paying for, hence the query that shows
all possible totals of payments and all possible totals of space charges.
What I am trying to avoid is using a payment of £147 to create 1 transaction
of £26.50, one of £52.50 and a third for the balance of £68 towards the
charge of £147. Then later, when a payment of £79 came in, there would be a
second transaction created against the £147 space for £79

I hate the way newsgroup readers seem to muck up displaying tables. If you
copy my example of the query into word, landscape and no margines, it is
easyier to read

Many thanks

Phil

Reply With Quote
  #4  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: Extracting data - 06-03-2010 , 09:33 AM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
On 02/06/2010 11:20:15, "Douglas J. Steele" wrote:

You've got a classic many-to-many relationship: one payment can apply to
multiple spaces, one space can be paid by multiple payments. That implies
you need three tables: one for payments, one for spaces, and one to
resolve that many-to-many relationship.

Thanks for coming back Douglas.

I have the thre tables that you mentioned. I know what spaces a person has
and their cost. I know the payments received. What I am tring to do is
deduce
from the payment which spaces he is paying for, hence the query that shows
all possible totals of payments and all possible totals of space charges.
What I am trying to avoid is using a payment of £147 to create 1
transaction
of £26.50, one of £52.50 and a third for the balance of £68 towards the
charge of £147. Then later, when a payment of £79 came in, there would be
a
second transaction created against the £147 space for £79

I hate the way newsgroup readers seem to muck up displaying tables. If you
copy my example of the query into word, landscape and no margines, it is
easyier to read
If you're trying to create all of the possible combinations of Cost and
Payment, about the idea of creating a Cartesian Product of the Spaces and
Payments tables?

See whether
http://www.databasejournal.com/featu...-MS-Access.htm
helps.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Extracting data - 06-06-2010 , 12:22 AM



On 03/06/2010 15:32:58, "Douglas J. Steele" wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in message
news:toSdne2wj5GNWJvRnZ2dnUVZ7vOdnZ2d (AT) brightview (DOT) co.uk...
On 02/06/2010 11:20:15, "Douglas J. Steele" wrote:

You've got a classic many-to-many relationship: one payment can apply to
multiple spaces, one space can be paid by multiple payments. That implies
you need three tables: one for payments, one for spaces, and one to
resolve that many-to-many relationship.

Thanks for coming back Douglas.

I have the thre tables that you mentioned. I know what spaces a person has
and their cost. I know the payments received. What I am tring to do is
deduce
from the payment which spaces he is paying for, hence the query that shows
all possible totals of payments and all possible totals of space charges.
What I am trying to avoid is using a payment of £147 to create 1
transaction
of £26.50, one of £52.50 and a third for the balance of £68 towards the
charge of £147. Then later, when a payment of £79 came in, there would be
a
second transaction created against the £147 space for £79

I hate the way newsgroup readers seem to muck up displaying tables. If you
copy my example of the query into word, landscape and no margines, it is
easyier to read

If you're trying to create all of the possible combinations of Cost and
Payment, about the idea of creating a Cartesian Product of the Spaces and
Payments tables?

See whether
http://www.databasejournal.com/featu...-MS-Access.htm
helps.

Sorry for the delay in coming back.

That is basically what I have done, and the example data that was on my
original post is the result of a query where basically I said show the
results where the sum of the payments matches the sum of the charges. My
problem is to reduce the 7 records in the query to the 3 records that I need
to create the transactions.

Thanks for your thoughts
Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.