473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL to count the number of nulls in a column

Hi,

What is the SQL to count the number of null values in a specific
column in a table?

I knw this must be simple but I've been Googling this for a long time
and have not the SQL to do this.

Thanks for the support,

Lee

Nov 28 '07 #1
6 7507
On Nov 28, 1:47 pm, leegold58 <goldt...@worldpost.comwrote:
Hi,

What is the SQL to count the number of null values in a specific
column in a table?

I knw this must be simple but I've been Googling this for a long time
and have not the SQL to do this.

Thanks for the support,

Lee
SELECT Count(Table.Field) AS FieldNullCount FROM Table HAVING
(((Count(Table.Field)) Is Null));
Nov 28 '07 #2
Sky
"DavidB" <je***@yahoo.comwrote in message
news:3c**********************************@r60g2000 hsc.googlegroups.com...
On Nov 28, 1:47 pm, leegold58 <goldt...@worldpost.comwrote:
>Hi,

What is the SQL to count the number of null values in a specific
column in a table?
>
SELECT Count(Table.Field) AS FieldNullCount FROM Table HAVING
(((Count(Table.Field)) Is Null));
I don't think so.

I suggest:
Select Count(*) From [MyTable] Where [MyField] Is Null

- Steve
Nov 28 '07 #3
On Nov 28, 2:01 pm, "Sky" <sky @ stanley associates . comwrote:
"DavidB" <je...@yahoo.comwrote in message

news:3c**********************************@r60g2000 hsc.googlegroups.com...
On Nov 28, 1:47 pm, leegold58 <goldt...@worldpost.comwrote:
Hi,
What is the SQL to count the number of null values in a specific
column in a table?
SELECT Count(Table.Field) AS FieldNullCount FROM Table HAVING
(((Count(Table.Field)) Is Null));

I don't think so.

I suggest:
Select Count(*) From [MyTable] Where [MyField] Is Null

- Steve
Same results. What I posted was what query builder generated. Only
difference is that mine adds an AS clause that will name the output
field whatever you want it named.
Nov 28 '07 #4
If the field you are counting is null, then the count does not work on
that field. Pick a different field to count that will ALWAYS have a
value.

Ron
Nov 28 '07 #5
leegold58 <go******@worldpost.comwrote in news:f4528c63-803d-4e01-
9b***************@j20g2000hsi.googlegroups.com:
Hi,

What is the SQL to count the number of null values in a specific
column in a table?

I knw this must be simple but I've been Googling this for a long time
and have not the SQL to do this.

Thanks for the support,

Lee
SELECT sum(iif(isnull(table.field),1,0) as nullCount from table;

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 28 '07 #6
Sky
>>
SELECT Count(Table.Field) AS FieldNullCount FROM Table HAVING
(((Count(Table.Field)) Is Null));

Select Count(*) From [MyTable] Where [MyField] Is Null
I was referring to the "Having" clause, not the "As" renaming.
But my prior comment "I don't think so" was inappropriate.

The aggregate "Having" clause is necessary for a criterion applied to an
aggregate function such as Count(), but the query engine must first select
and process all records, and only then evaluate the aggregate function
(Count in this case) against the criterion at the end.

The "Where" clause performs the filtering during the initial record scan
prior to computing any aggregate functions, so it is more efficient. In
general, a Where clause is preferred over a Having clause. The difference is
negligible for small tables, but Where is recommended when possible.

On the other, a Having clause is necessary if you want a criterion like
"Having Min([MyField]) < 10", but it is not needed here for a filtering
criterion such as Is Null.

- Steve
Nov 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
44082
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
5
10752
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
3
2000
by: aaj | last post by:
Hi I am probably going to regret asking this because I'm sure you are going to tell me my design is bad 8-) ah well we all have to learn.... anyway I often use Nulls as a marker to see if...
5
3137
by: gelangov | last post by:
I need to update the columns to blanks if it has Nulls; Most of the time we do not have Nulls and to check that in a 3.2 million table it takes 2 minutes and 45 seconds. (To do select count(*) from...
8
6356
by: Doug Bell | last post by:
Hi, I need to create a function that will return the number of columns in a passed reference to a DataView. I can find the number of columns in its underlying Data table but have not been...
68
6747
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
4502
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
1
3616
by: rsbutterfly16 via AccessMonster.com | last post by:
hi guys i have form with a listbox . The listbox is coming from a query that gets all passengers(column 1 in listbox) and destinations(column 3) . so you have repeting rows of passengers since...
22
12425
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.