Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2006

Tip: Looking for answers? Try searching our database.

Problems with COUNT in Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 29 May 2006 05:37 GMT
hello,
I have a somewhat LONG sql query that's not working for me.  Seems simple
enough.  I have two tables.  I just want to count the number of times the
record appears in the sub-table.

Main Table is Donors
Sub Table is Donations
Goal is to display donor info and the number of time the donor has made
Donations.

here is the big ol SQL.  Can someone tell me what I'm doing wrong?

SELECT Donors.[Company Name], Donors.[First Name], Donors.[Last Name],
Donors.[Mailing Address 1], Donors.[Mailing Address 2], Donors.City,
Donors.State, Donors.[Zip Code], Format([Date Collected],"yyyy") AS [Year
Collected], IIf([Title]<>"",[Title] & " " & [First Name] & " " & [Last Name]
& " " & [Suffix],[First Name] & " " & [Last Name] & " " & [Suffix]) AS
Full_Name, [City] & ", " & [State] & "  " & [Zip Code] AS City_St_Zip,
Donors.Title, Donors.Suffix, Donations.[Date Collected], Donors.[Donor ID
Number], Count(Donations.[Donor ID Number]) AS [CountOfDonor ID Number]
FROM Donors INNER JOIN Donations ON Donors.[Donor ID Number] =
Donations.[Donor ID Number]
GROUP BY Donors.[Company Name], Donors.[First Name], Donors.[Last Name],
Donors.[Mailing Address 1], Donors.[Mailing Address 2], Donors.City,
Donors.State, Donors.[Zip Code], Format([Date Collected],"yyyy"),
IIf([Title]<>"",[Title] & " " & [First Name] & " " & [Last Name] & " " &
[Suffix],[First Name] & " " & [Last Name] & " " & [Suffix]), [City] & ", " &
[State] & "  " & [Zip Code], Donors.Title, Donors.Suffix, Donations.[Date
Collected], Donors.[Donor ID Number]
HAVING (((Donations.[Date Collected]) Between [Forms]![Filter Criteria Donor
Reports].[txtStartDate] And [Forms]![Filter Criteria Donor
Reports].[txtEndDate]));
arthurjr07@gmail.com - 29 May 2006 06:29 GMT
Try this..

SELECT Donors.*, A.CNT FROM Donors INNER JOIN
(SELECT Donations.[Donor ID Number] , Count(*) AS CNT
FROM Donations GROUP BY Donations.[Donor ID Number]) AS A
ON Donors.[Donor ID Number] = A.[Donor ID Number]
Marshall Barton - 29 May 2006 07:10 GMT
>I have a somewhat LONG sql query that's not working for me.  Seems simple
>enough.  I have two tables.  I just want to count the number of times the
[quoted text clipped - 27 lines]
>Reports].[txtStartDate] And [Forms]![Filter Criteria Donor
>Reports].[txtEndDate]));

Two quick observations.

Get rid of the Donations.[Date Collected] fielld in the
SELECT clause.

Change the HAVING to WHERE.

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.