SQL: Fetch all the fields that are NULL
Monday, 04 February 2008


The following SQL (select statement) won't return an error. BUT it won't return a record either.

select * from YourTable where YourField = NULL

In SQL, NULL is not a value but a state indicating that an item's value is unknown or nonexistent. It is not zero or blank or an “empty string” and it does not behave like any of these values. Few things in SQL lead to more confusion than NULL, and yet its workings shouldn't be hard to understand as long as you stick to the following simple definition: NULL means unknown. [Firebird]


Hence the ff. statement won't return the NULL fields: 

select * from YourTable where YourField = ''

IsNull function won't work because it requires some parameters/arguments. The fact that it is a function. 

Here's a statement that would work with NULLs:

select * from YourTable where YourField is Null

I should remember those two words. I kept on forgetting. Cool

 

 

Readers have left 2 comments.
 1. Untitled
Guest, Unregistered
you are an optimist! I am a pessimist with nulls.

and thus:

select * from [Table] where [Field] is not null
 Posted 2008-02-04 06:24:43
 2. Untitled
mae, Unregistered
NULLS freak me out
 Posted 2008-02-04 18:51:34
Please keep your comments brief and on topic, and remember that this is not a discussion thread.
Name :
E-mail :
Website :
Comment(s) :
J! Reactions 1.09.00 • General Site License
Copyright © 2006 S. A. DeCaro
 
< Prev   Next >