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
๐ŸŒ
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

๐ŸŒ
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:
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ sql โ€บ is_not_null.php
SQL: IS NOT NULL Condition
The IS NOT NULL condition is used in SQL to test for a non-NULL value. It returns TRUE if a non-NULL value is found, otherwise it returns FALSE.
๐ŸŒ
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.
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.

๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ answers โ€บ questions โ€บ 387709 โ€บ not-null-property-in-sql-server-express-2019
"NOT NULL" property in SQL Server Express 2019 - Microsoft Q&A
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 1 comment Show comments for this answer Report a concern ... Muchas gracias por tu respuesta. ... Probably you are inserting empty strings (โ€˜โ€™), which are not null.
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql server โ€บ how-to-check-a-column-is-empty-or-null-in-sql-server
How to Check a Column is Empty or Null in SQL Server - GeeksforGeeks
January 31, 2024 - The function ISNULL() returns all records with 'NULL' values and records having Empty value ('') or Spaces (' ') in the specified column. ... Expression can be a column name and replacement is the string value which will replace the column value.