Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a column is empty or null using SQL query select statement?

Tags:

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 
like image 414
NoviceToDotNet Avatar asked Jan 24 '11 08:01

NoviceToDotNet


People also ask

Is NULL or empty in SQL query?

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.

Is blank in SQL query?

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.

How do you check if a column is blank?

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 "".


2 Answers

Does this do what you want?

SELECT * FROM UserProfile WHERE PropertydefinitionID in (40, 53)   AND (    PropertyValue is NULL         or PropertyValue = '' ); 
like image 110
Christian Severin Avatar answered Sep 30 '22 21:09

Christian Severin


Here's a slightly different way:

SELECT * FROM UserProfile WHERE PropertydefinitionID in (40, 53)   AND (LEN(ISNULL(PropertyValue,'')) = 0) 
like image 31
Denis Ivin Avatar answered Sep 30 '22 20:09

Denis Ivin