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
select * from table_name where boolean_column is null; works well. Give the result with all transaction having null value for that column.
Boolean is a reference type, that's the reason you can assign null to a Boolean "variable". Example: Boolean testvar = null; if (testvar == null) { ...} Yes, because then hideInNav holds a reference to a Boolean object and can be null (no reference assigned).
BOOLEAN can have TRUE or FALSE values. BOOLEAN can also have an “unknown” value, which is represented by NULL. Boolean columns can be used in expressions (e.g. SELECT list), as well as predicates (e.g. WHERE clause).
Nullable boolean can be null, or having a value “true” or “false”. Before accessing the value, we should verify if the variable is null or not. This can be done with the classical check : if … else …
In TSQL, you need to use IS
rather than =
when comparing with NULL
:
SELECT * FROM table WHERE field IS NULL
Try
select * from table where field IS null
You want IS NULL
I believe:
SELECT * FROM table WHERE field IS NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With