Sunday, February 19, 2012

How to Query for NULL in a database

In my database, in a few tables there are NULL values in some of the columns. This is okay, but I need to know how to query for nulls. For example I tried the following query but it did not work:

select*from Employeewhere DateOfBirth=NULL

This did not work so I also tried the following:

select*from Employeewhere DateOfBirth='NULL'

Neither of these worked. Can someone help me out?

NULL means unknown. So 2 NULLs are not equal. Read up books online about NULLs. Its an important topic. For your query, you would need to write it as:

SELECT * FROM Employee WHERE DateOfBirthIS NULL

No comments:

Post a Comment