13

I have a field in a table that is boolean, a range of records have no value (not true or false). How do I write my SQL statement to find these?

I have tried the following SQL statements without success:

1) SELECT * FROM table WHERE field = NULL
2) SELECT * FROM table WHERE field != TRUE AND field != FALSE

Any help would be greatly appreciated.

Many Thanks, Ben

3
  • Thanks for all your answers, esp/ Mitch Wheat :) Commented Jun 11, 2009 at 15:05
  • NULL is not a value, it's absence of value. Thus no value could be compared to the absence of value. Commented Jun 11, 2009 at 15:23
  • 1
    @Milen: Pretty much every other language manages this just fine. IMO it's extremely dumb that SQL needs a different operator for this Commented Jul 9, 2009 at 11:57

3 Answers 3

31

In TSQL, you need to use IS rather than = when comparing with NULL:

SELECT * FROM table WHERE field IS NULL
Sign up to request clarification or add additional context in comments.

Comments

6

Try

select * from table where field IS null

Comments

4

You want IS NULL I believe:

SELECT * FROM table WHERE field IS NULL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.