If you only want to match "" as an empty string

WHERE DATALENGTH(COLUMN) > 0 

If you want to count any string consisting entirely of spaces as empty

WHERE COLUMN <> '' 

Both of these will not return NULL values when used in a WHERE clause. As NULL will evaluate as UNKNOWN for these rather than TRUE.

CREATE TABLE T 
  ( 
     C VARCHAR(10) 
  ); 

INSERT INTO T 
VALUES      ('A'), 
            (''),
            ('    '), 
            (NULL); 

SELECT * 
FROM   T 
WHERE  C <> ''

Returns just the single row A. I.e. The rows with NULL or an empty string or a string consisting entirely of spaces are all excluded by this query.

SQL Fiddle

Answer from Martin Smith on Stack Overflow
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › check-the-variable-is-empty-or-null
Check the Variable is Empty or Null – SQLServerCentral Forums
September 9, 2014 - Edit: sql code tag messed up my "greater than" symbol. You may do it... sometimes... But it is NOT right. Try this: ... If you want to make sure that your varchar value contains some thingelse than NULL and empty string use simple "NOT EQUAL" eg:
🌐
W3Schools
w3schools.com › sql › sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
The IS NOT NULL operator is used to test for non-empty values (NOT NULL values). The following SQL lists all customers with a value in the "Address" field:
🌐
Reddit
reddit.com › r/sql › how to handle a value which is not null but also not an empty string?
r/SQL on Reddit: How to handle a value which is not null but also not an empty string?
March 12, 2024 -

I have a table which contains some values which are not null. I thought it might be an empty sting but it was not an empty string either.

I copied that particular field from the table and tried an update statement to convert it into null but it didn't worked either . Kindly suggest something

🌐
Baeldung
baeldung.com › home › sql queries › find null or empty values in sql
Find Null or Empty Values in SQL Baeldung on SQL
August 20, 2025 - The TRIM function removes whitespaces ... the first non-NULL value from a list of arguments. COALESCE(code, ”) returns the value of the column code if it is not NULL....
🌐
Alteryx
community.alteryx.com › t5 › Alteryx-Server-Discussions › SQL-query-for-empty-string-data-type › td-p › 960668
Solved: SQL query for empty string data type - Alteryx Community
June 29, 2022 - here is my SQL: SELECT RPPO, RPPDCT, RPOBJ, RPSUB, RPVINV, RPDIVJ, RPLNID, RPPYIN, RPSBL, RPSBLT, RPDOC FROM JDESTAGE.F0411_LT where RPDIVJ>=122001 and RPPO is not NULL ... Solved! Go to Solution. ... Solved! Go to Solution. ... I did try this but didn't work out. ... @tectonics25 are you getting an error message? Or it’s just leaving empty values in?
🌐
Quora
quora.com › What-is-the-standard-SQL-query-for-checking-null-or-empty-strings
What is the standard SQL query for checking null or empty strings? - Quora
Answer (1 of 2): In standard SQL, you can use the [code ]IS NULL[/code] predicate to check if a value is [code ]NULL[/code]. To check for empty strings, you can use the [code ]IS NULL[/code] predicate along with the [code ]LENGTH[/code] function (or ...
Find elsewhere
Top answer
1 of 11
92

Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

2 of 11
28

I do not know about MySQL and PostgreSQL, but let me treat this a bit generally.

There is one DBMS namely Oracle which doesn't allow to choose it's users between NULL and ''. This clearly demonstrates that it is not necessary to distinguish between both. There are some annoying consequences:

You set a varchar2 to an empty string like this:

Update mytable set varchar_col = '';

the following leads to the same result

Update mytable set varchar_col = NULL;

But to select the columns where the value is empty or NULL, you have to use

select * from mytable where varchar_col is NULL;

Using

select * from mytable where varchar_col = '';

is syntactically correct, but it never returns a row.

On the other side, when concatenating strings in Oracle. NULL varchars are treated as empty strings.

select NULL || 'abc' from DUAL;

yields abc. Other DBMS would return NULL in these cases.

When you want to express explicitly, that a value is assigned, you have to use something like ' '.

And you have to worry whether trimming not empty results in NULL

select case when ltrim(' ') is null then 'null' else 'not null' end from dual

It does.

Now looking at DBMS where '' is not identical to NULL (e.g. SQL-Server)

Working with '' is generally easier and in most case there is no practical need to distinguish between both. One of the exceptions I know, is when your column represents some setting and you have not empty defaults for them. When you can distinguish between '' and NULL you are able to express that your setting is empty and avoid that the default applies.

🌐
YouTube
youtube.com › watch
SQL NULL vs Empty String vs Blank Space Explained | #SQL Course 19 - YouTube
🎬 *SQL Full (30-Hours) Course* https://youtu.be/SSKVgrwhzus🎁 *Free Downloads & Materials:* https://datawithbaraa.substack.com👉 *Support & Subscribe* to Ch...
Published   July 30, 2024
🌐
Ercanopak
blog.ercanopak.com › how-to-check-for-is-not-null-and-is-not-empty-string-in-sql
How to check for ‘IS NOT NULL’ And ‘IS NOT EMPTY’ string in SQL – ErcanOPAK.com
SQL · - 09.04.21 - ErcanOPAK · If you only want to match N” as an empty string · SELECT COLUMN FROM TABLE WHERE DATALENGTH(COLUMN) > 0 · If you want to count any string consisting entirely of spaces as empty · SELECT COLUMN FROM TABLE WHERE COLUMN <> '' If you want to use DATALENGTH ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › mdx › working-with-empty-values
Working with Empty Values - SQL Server | Microsoft Learn
Between the empty cell value and the empty string, empty collates before an empty string. In Multidimensional Expressions (MDX) statements, you can look for empty values and then perform certain calculations on cells with valid (that is, not empty) data.
🌐
SQL Training Online
sqltrainingonline.com › home › blog › sql training › how to filter for sql null or empty string
How to Filter for SQL Null or Empty String - SQL Training Online
November 9, 2012 - It is a special “value” that you can’t compare to using the normal operators. You have to use a clause in SQL IS Null. On the other hand, an empty string is an actual value that can be compared to in a database.
🌐
InterSystems
community.intersystems.com › post › sql-server-how-write-column-empty-string-instead-null
SQL Server - How to write column with empty string instead of NULL |
0 0 https://community.intersystems.com/post/sql-server-how-write-column-empty-string-instead-null#comment-122561 ... I have not tested this but from what I read about ISNULL(), this might work.
🌐
Skynats
skynats.com › home › understanding sql server coalesce with empty strings: a comprehensive guide
Understanding SQL Server COALESCE with Empty Strings: A Comprehensive Guide
April 3, 2025 - The COALESCE function evaluates ... that is not NULL. If all expressions are NULL, it returns NULL. One of the primary use cases for COALESCE is replacing NULL values with a default or known value. For example, you can use it to return a fallback value when a column contains NULL. An empty string (”) is a string that contains no characters. It’s different from a NULL value, which represents the absence of a value. Empty strings are valid data in SQL and can be ...
🌐
Alibaba Cloud Community
alibabacloud.com › blog › when-to-use-null-and-when-to-use-empty-string_598579
When to Use NULL and When to Use Empty String - Alibaba Cloud Community
Note: It will take some time to prepare and launch your instance. Once the state of your instance is running, you can manage it from the console. The concept of NULL and empty string often creates confusion since many people think NULL is the same as a MySQL empty string.