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

cpunting yes/no

Status
Not open for further replies.

mrk2

Technical User
Aug 19, 2002
76
0
0
US
How can I count the number of unchecked or checked yes/no entries from a table in a query? when I use the "count" feature it shows no data in the query?
 
If I'm understaing correctly, you must use a group by query like:

SELECT TableA.myyesno, Count(TableA.myyesno) AS CountOfmyyesno
FROM TableA
GROUP BY TableA.myyesno;


J. Jones
jjonesal@cableone.net
 
ok here is what I got from your post. Both the table and the cloumn are called attendance, which probably isnt the smartst thing in the world. Where does this code go, I'm not sure what to do with this?

SELECT Tableattendance.attendance, Count(attendance.attendance) AS CountOfattendance
 
If you are saying that the Attendance column in your Attendance table is a Yes/No then:

SELECT Attendance.Attendace, Count(Attendance.Attendance) AS CountOfAttendace
FROM Attendance
GROUP BY Attendance.Attendance;

Create a new query using the design view. Select View, SQL from the menu at the top and copy and paste the above code. Then, you can execute the query or go back to Design view (View, Design View) to see the graphical representation of the query.


J. Jones
jjonesal@cableone.net
 
ok I need to add a twist to this, this data needs to be sorted by another data element in that table. Do I write
GROUP BY Attendance.ID;
rather than
GROUP BY Attendance.Attendance;

???????????
 
No, you use an ORDER BY clause to do the sorting. J. Jones
jjonesal@cableone.net
 
and an ORDER BY clause looks like....?
 
ORDER BY Attendance.ID


An ORDER BY clause simply lists all fields on which you want to sort and comes after the GROUP BY.

ORDER BY a, b, c

would sort first by field a, then within that by field b, then within that b field c. An ascending sort is the default, but you could include DESC after a field to indicate that the sort should be descending.

ORDER BY a, b DESC, c

would sort first ascending by a, then within that descending by b, and then within that ascending by c

J. Jones
jjonesal@cableone.net
 
Add two expression fields to your query:
Code:
CountYes: DCount("[yesnofield]","yourtable","[yesnofield]=Yes")

CountNo: DCount("[yesnofield]","yourtable","[yesnofield]=No")
 
Using aggregate queries (particularly COUNT) obviates the use of order by. It (the aggregate "COUNT" will only return the single record, so ordering is 'moot'.

Further, the Count (query) -as shown- will simply show the number of records, as the boolean (Yes / No) field will always be either &quot;True&quot; ( <> 0) or &quot;False&quot; ( = 0). Depending on the 'real' need, you can count the &quot;true&quot; (or false) entries by including a Where clause for the field.


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
What is wrong with the following Order BY clause???

SELECT Attendance.attendance AS Expr1, Count(Attendance.attendance) AS CountOfAttendance
FROM Attendance
GROUP BY Attendance.attendance
ORDER BY Attendance.ID;
 
see previous post. How many 'results' do you get? then think about how it even CAN be ordered.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top