473,287 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Problems Querying Last Donation in Donation Table

Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and
have found leads to the answers to several other problems I have encountered
with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few
evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a
similar query for when volunteers were last scheduled.
Nov 12 '05 #1
3 1999
I think if you have 1 query (Query1) just returning the CntcID and the
LastOfDNDate, and then create a second query with whatever information you
want. That would consist of your 2 table + Query 1 but join the 2 CntcIDs
and the LastOfDNDate to the DNDate. That should only pull information
applicable to the last donation date
HTH

Phil
"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message
news:vv************@corp.supernews.com...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and have found leads to the answers to several other problems I have encountered with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a similar query for when volunteers were last scheduled.

Nov 12 '05 #2
as a quick test, I created tblOne
id (pk)
lastName

id lastname
1 cane
2 able

and tblTwo
id (pk) (uk)
seq (pk)
date (uk)
donation

id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/6/2004 11

since you want the donation for the last date, I assume that every
date in tblTwo is unique ?

then I created qry2
SELECT tblTwo.id, Last(tblTwo.date) AS LastOfdate
FROM tblTwo
GROUP BY tblTwo.id;

id lastDate
1 1/4/2004
2 1/6/2004
then I created qry1
SELECT tblOne.lastName, qry2.LastOfdate, tblTwo.donation
FROM (tblOne INNER JOIN qry2 ON tblOne.id = qry2.id) INNER JOIN
tblTwo ON
(qry2.LastOfdate = tblTwo.date) AND (qry2.id = tblTwo.id);
^^^^ - this is based on my assumption above

lastName lastDate donation
cane 1/4/2004 9
able 1/6/2004 11

is this what you need ?
if my assumption is incorrect, which donation amount would you want
for id 2 ?
id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/5/2004 11

"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message news:<vv************@corp.supernews.com>...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and
have found leads to the answers to several other problems I have encountered
with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few
evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a
similar query for when volunteers were last scheduled.

Nov 12 '05 #3
Phil & Roger,
Thanks for your help.
Phil had the right answer,[twin/dbl join] but something Roger said tipped me
off to my mistake. "I assume that every date in tblTwo is unique"

The donations table has about 900 records. When drilled down with the Last
query it returns about 350 records - one date for each donor -however what
was throwing me off was that many donors have multiple donations on the SAME
day....

Had I realized this 18 months ago I would have created a "donation date"
table with related "donated items" table... [so now I have to wrestle with
changing that data "for the long term good" or "its not that important"]

Thanks again!
Andy

"Roger" <le*********@natpro.com> wrote in message
news:8c**************************@posting.google.c om...
as a quick test, I created tblOne
id (pk)
lastName

id lastname
1 cane
2 able

and tblTwo
id (pk) (uk)
seq (pk)
date (uk)
donation

id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/6/2004 11

since you want the donation for the last date, I assume that every
date in tblTwo is unique ?

then I created qry2
SELECT tblTwo.id, Last(tblTwo.date) AS LastOfdate
FROM tblTwo
GROUP BY tblTwo.id;

id lastDate
1 1/4/2004
2 1/6/2004
then I created qry1
SELECT tblOne.lastName, qry2.LastOfdate, tblTwo.donation
FROM (tblOne INNER JOIN qry2 ON tblOne.id = qry2.id) INNER JOIN
tblTwo ON
(qry2.LastOfdate = tblTwo.date) AND (qry2.id = tblTwo.id);
^^^^ - this is based on my assumption above

lastName lastDate donation
cane 1/4/2004 9
able 1/6/2004 11

is this what you need ?
if my assumption is incorrect, which donation amount would you want
for id 2 ?
id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/5/2004 11

"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message

news:<vv************@corp.supernews.com>...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex each time... I have learned much and read much over the last few months and have found leads to the answers to several other problems I have encountered with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a similar query for when volunteers were last scheduled.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
8
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ...
4
by: pietlinden | last post by:
Hi, I have the sort of standard Donors/Donations DB. The twist I have is that donations can be time, money (which are easy, because they're additive), but then a donor can make an in-kind pledge,...
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
2
by: bwana.mpoa | last post by:
Hi, We're using a mySQL database as a replica of another (Sybase) DB for reporting purposes. The Sybase is part of a real-time mission critical system - hence the separate database where people...
2
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding :...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.