How do I check if a column is empty or null using a SQL select statement?
For instance, if I want to check:
select * from UserProfile WHERE PropertydefinitionID in (40, 53) and PropertyValue is null or empty
NULL is used in SQL to indicate that a value doesn't exist in the database. It's not to be confused with an empty string or a zero value. While NULL indicates the absence of a value, the empty string and zero both represent actual values.
The SQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different than a zero value or a field that contains spaces.
Re: Determine if column is empty The formula =COUNTA(A1:A100) will return the number of non-blank cells in the range A1:A100. So if this formula returns 0, the range A1:A100 is completely empty. Warning: a cell containing a formula counts as a non-blank cell, even if that formula returns the empty string "".
Does this do what you want?
SELECT * FROM UserProfile WHERE PropertydefinitionID in (40, 53) AND ( PropertyValue is NULL or PropertyValue = '' );
Here's a slightly different way:
SELECT * FROM UserProfile WHERE PropertydefinitionID in (40, 53) AND (LEN(ISNULL(PropertyValue,'')) = 0)
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