473,662 Members | 2,524 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 7520
On Nov 28, 1:47 pm, leegold58 <goldt...@world post.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.Fie ld) AS FieldNullCount FROM Table HAVING
(((Count(Table. Field)) Is Null));
Nov 28 '07 #2
Sky
"DavidB" <je***@yahoo.co mwrote in message
news:3c******** *************** ***********@r60 g2000hsc.google groups.com...
On Nov 28, 1:47 pm, leegold58 <goldt...@world post.comwrote:
>Hi,

What is the SQL to count the number of null values in a specific
column in a table?
>
SELECT Count(Table.Fie ld) 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.co mwrote in message

news:3c******** *************** ***********@r60 g2000hsc.google groups.com...
On Nov 28, 1:47 pm, leegold58 <goldt...@world post.comwrote:
Hi,
What is the SQL to count the number of null values in a specific
column in a table?
SELECT Count(Table.Fie ld) 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******@world post.comwrote in news:f4528c63-803d-4e01-
9b************* **@j20g2000hsi. googlegroups.co m:
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.Fie ld) 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
44098
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 scott/tiger@common control=/full_path/test.ctl log=/full_path/adhoc/test.log SQL*Loader: Release 9.2.0.1.0 - Production on Tue Sep 2 10:49:27 2003 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
5
10767
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 message "Column count doesn't match value count at row 1".
3
2010
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 certain tasks have been completed. A typical example would be a column say invoice_value
5
3145
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 <table> where <columnname> is Null) . I just cut and pasted a part from my stored procedure: EXEC ('IF (SELECT COUNT (*) FROM ' + @tblname + ' WHERE ' +@columnname + ' is Null ) >0 BEGIN
8
6366
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 able to find a way of determining the column count in the DataView. Thanks for any assistance.
68
6795
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
4517
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 have created an access query to track the number of training hours for a training group. The query is working except for one piece of data and I hoping someone can help me. There is a field titled enrollment status, which presents an alpha character of...
1
3621
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 they could have up to three destinations. Then the user has to select a row in the list box , double click even in my listbox i have to sql query to delete the currect item selected (passenger with destination). this works fine. however i need to put...
22
12464
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=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7367
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.