Calculate empty fields (isNull)? (1 Viewer)

azhar2006

Registered User.
Local time
Today, 08:15
Joined
Feb 8, 2012
Messages
202
I have a select query that calculates the Count of certain and gives me the result of the sum of each specialty. Some records are empty and there is no specific specialization. What I want is to calculate these empty fields as well.
Code:
SELECT tblMastr.adjAppo, Count(tblMastr.adjAppo) AS CountOfadjAppo
FROM tblMastr
GROUP BY tblMastr.adjAppo;
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:15
Joined
May 7, 2009
Messages
19,245
SELECT tblMastr.adjAppo, Count("1") AS CountOfadjAppo
FROM tblMastr
WHERE ((tblMastr.adjAppo) Is Null)
GROUP BY tblMastr.adjAppo;
 

azhar2006

Registered User.
Local time
Today, 08:15
Joined
Feb 8, 2012
Messages
202
SELECT tblMastr.adjAppo, Count("1") AS CountOfadjAppo
FROM tblMastr
WHERE ((tblMastr.adjAppo) Is Null)
GROUP BY tblMastr.adjAppo;
Thanks my friend for the quick reply. This is not what I mean. I have attached a database to you. Note in the table there are two employees who do not have any capacity. But the query shows that those who do not have the attribute are zero.
 

Attachments

  • ANo.zip
    19.4 KB · Views: 334
  • 33.JPG
    33.JPG
    25.4 KB · Views: 289

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:15
Joined
May 7, 2009
Messages
19,245
i used Union query (see the modified query).
 

Attachments

  • ANo.zip
    23.6 KB · Views: 339

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2002
Messages
43,275
Did you try arnel's original solution? It should have worked.

Count(somefield) -- ignores records where somefield is null.

Count(*) -- the normal way which counts all rows returned by the query regardless of the value in any particular field. People mistakenly think that they have to put the name of the field they think they are counting in the Count() expression but Count() does NOT count individual values. It counts ROWS for the recordset or group by clause.

Count("1") is obtuse but should have worked.
 

azhar2006

Registered User.
Local time
Today, 08:15
Joined
Feb 8, 2012
Messages
202
Did you try arnel's original solution? It should have worked.

Count(somefield) -- ignores records where somefield is null.

Count(*) -- the normal way which counts all rows returned by the query regardless of the value in any particular field. People mistakenly think that they have to put the name of the field they think they are counting in the Count() expression but Count() does NOT count individual values. It counts ROWS for the recordset or group by clause.

Count("1") is obtuse but should have worked.
Thank you so much . You are very accurate, it worked well too.
Code:
SELECT TableA.Specialty, Count("1") AS CountOfSpecialty
FROM  TableA
GROUP BY TableA.Specialty;
 

Attachments

  • image_2021-11-05_220152.png
    image_2021-11-05_220152.png
    16.5 KB · Views: 304

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2002
Messages
43,275
If you do a count like this for a text field and you ever end up with two "blank" rows, one row will be the null values and the other row will be the ZLS (Zero Length String) values.
 

Users who are viewing this thread

Top Bottom