View Full Version : Count Unique URNs


JoysTick
12-11-2001, 04:14 AM
I'm trying to count the number of Unique ClientURNs of Male or Females answering Yes to each question returned by this query.

SELECT DISTINCTROW qry1MajorFilterClients.ClientURN, qry1MajorFilterClients.Gender, [1 Client Visits].[Housing-SeekingHousing], [1 Client Visits].[Housing-Repair], [1 Client Visits].[Housing-Landlord], [1 Client Visits].[Housing-Neighbour], [1 Client Visits].[Housing-Other]
FROM [1 Client Visits] INNER JOIN qry1MajorFilterClients ON [1 Client Visits].ClientURN = qry1MajorFilterClients.ClientURN
GROUP BY qry1MajorFilterClients.ClientURN, qry1MajorFilterClients.Gender, [1 Client Visits].[Housing-SeekingHousing], [1 Client Visits].[Housing-Repair], [1 Client Visits].[Housing-Landlord], [1 Client Visits].[Housing-Neighbour], [1 Client Visits].[Housing-Other]
HAVING ((([1 Client Visits].[Housing-SeekingHousing])=-1)) OR ((([1 Client Visits].[Housing-Repair])=-1)) OR ((([1 Client Visits].[Housing-Landlord])=-1)) OR ((([1 Client Visits].[Housing-Neighbour])=-1)) OR ((([1 Client Visits].[Housing-Other])=-1));

I'm wanting to reference the answer to a report, using for example, for just one of the questions,:
=DCount("[qryZHousing-SeekingHousing]![ClientURN]","[qryZHousing-SeekingHousing]","([Housing-SeekingHousing] = - 1) AND (Gender=2)")
Each question total on the report would have a similar source.

Am I on the right track, or should I take up another interest... :-)

Pat Hartman
12-11-2001, 07:27 PM
Your table is not normalized. Therefore, you will need a separate query for each question field to properly count them.

JoysTick
12-12-2001, 12:24 AM
Pat,

Thanks for the reply, I'd reluctantly come to that conclusion myself, :-(

What field/table structure would be better to normalize this situation?

Thanks
JS

Pat Hartman
12-12-2001, 05:29 AM
If you create a new table to hold the questions, you'll have much less trouble calculating statistics. The table would be something like:

tblAnswers
Whatever key you use for the current table (primary key field 1)
QuestionId (primary key field 2, foreign key to tblQuestions)
Answer

There would also be a "lookup" table to define the questions:

tblQuestions
QuestionId (primary key)
QuestionText