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

Yes/No column counts all. 1

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi,
I have a problem trying to count a Yes/No column in my query. The column is being counted as if all the boxes are ticked but this is not the case. Does anyone know how to sort this.
 
Hi Les,
Thanks for replying, the Sql is:

SELECT tblprofiles.Jobfamily, Count(tblassimilation.PayNumber) AS CountOfPayNumber, Count(tblassimilation.KSF) AS CountOfKSF
FROM tblassimilation RIGHT JOIN tblprofiles ON tblassimilation.[Post Descriptor] = tblprofiles.Postdescriptor
GROUP BY tblprofiles.Jobfamily;

at the moment both columns are counting the same although there is only 1 box ticked in the KSF field and the payNumber field should be a count of all the staff.
 
if you only want to count the field if it's checked then, here's one way:

SUM(iif(tblassimilation.KSF, 1, 0)

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Thanks Les,
Thats exactly what I was looking for.

SELECT tblprofiles.Jobfamily, Count(tblassimilation.PayNumber) AS StaffCount, Sum(IIf([tblassimilation].[KSF],1,0)) AS KSFCount
FROM tblassimilation RIGHT JOIN tblprofiles ON tblassimilation.[Post Descriptor] = tblprofiles.Postdescriptor
GROUP BY tblprofiles.Jobfamily;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top