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
🌐
Alteryx
community.alteryx.com › home › participate › discussions › alteryx server
SQL query for empty string data type - Alteryx
June 28, 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 ... I did try this but didn't work out. ... @tectonics25 are you getting an error message? Or it’s just leaving empty values in?
Discussions

sql server - How to use NULL or empty string in SQL - Stack Overflow
I would like to know how to use NULL and an empty string at the same time in a WHERE clause in SQL Server. I need to find records that have either null values or an empty string. Thanks. ... There's an OR keyword in SQL. ... This question does not show any research effort. More on stackoverflow.com
🌐 stackoverflow.com
sql server - SQL statement to check for empty string - T-SQL - Stack Overflow
Yields 1. From what I can gather on Wikipedia, this particular unicode character is a pictograph for submerging something, which is not semantically equal to an empty string. Also, the string length is 1, at least in T-SQL. More on stackoverflow.com
🌐 stackoverflow.com
What is the best practice for querying if a TEXT column is not empty?
Index a prefix of the notes field. ... INDEX(notes(1)) More on reddit.com
🌐 r/mysql
3
2
December 7, 2023
Check the Variable is Empty or Null – SQLServerCentral Forums
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: More on sqlservercentral.com
🌐 sqlservercentral.com
September 9, 2014
🌐
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 5, 2026 - The TRIM function removes whitespaces from a string’s beginning and end, allowing us to compare it against an empty character. ... The COALESCE function in SQL returns the first non-NULL value from a list of arguments. COALESCE(code, ”) returns the value of the column code if it is not NULL.
🌐
AI2SQL
ai2sql.io › home › blog › how to write an sql query to select only non-empty values
How to Write an SQL Query to Select Only Non-Empty Values - SQL Query Builder & Generator - AI Powered Database Assistant
To select rows where a specific column isn’t empty, you need to check for both NULL and empty string (''). Here’s how you can do it: SELECT * FROM customers WHERE email IS NOT NULL AND email <> ''; This query ensures that only customers ...
🌐
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 – Bits of .NET
April 9, 2021 - Daily micro-tips for C#, SQL, performance, and scalable backend engineering. ... If you want to use DATALENGTH for any string consisting entirely of spaces then you must use LTRIM(RTRIM(COLUMN)) before.
Find elsewhere
🌐
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 3): 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 its equivalent for your database system) to che...
🌐
Bram.us
bram.us › 2007 › 07 › 05 › my-dotd-ms-sql-check-for-empty-string
My DOTD : MS SQL Check for empty String – Bram.us
Erm Nathan, check this quote from the post above: “There is no mysql_last_insert_id alike function for MS SQL, you have to work with identity columns and fire an extra query at the server to get the last inserted id;” · –>> that part about “fire an extra query at the server” is that scope_identity you've mentioned ;) ... For me, when I used LIKE ‘_%’ , my results were the same. Using (NOT (myField LIKE ”)) didn’t return the empty strings, but also didn’t return the null values.
🌐
Devart
devart.com › home › how to › how to handle null or empty values in sql server
Null vs. Empty Values in SQL Server — Queries and Techniques
December 19, 2024 - As we mentioned earlier, an empty ... value. SQL Server treats them differently, and using the IS NULL operator in a query with the WHERE condition does not return empty strings....
🌐
tutorialpedia
tutorialpedia.org › blog › how-to-check-for-is-not-null-and-is-not-empty-string-in-sql-server
How to Check for NOT NULL and NOT Empty String in SQL Server WHERE Clause — tutorialpedia.org
While NULL and empty strings might seem similar, they represent distinct concepts in SQL: NULL indicates the absence of a value, while an empty string is a valid (though zero-length) string value. This blog post will demystify how to check for NOT NULL and NOT Empty String in the WHERE clause, explore common pitfalls, and provide practical examples to ensure your queries return accurate results.
🌐
Reddit
reddit.com › r/mysql › what is the best practice for querying if a text column is not empty?
r/mysql on Reddit: What is the best practice for querying if a TEXT column is not empty?
December 7, 2023 -

This is a simplified query. The original is very long against a very large table:

SELECT * from table where notes <> "";

The `notes` column is a text field and since it has no defined length, it cannot be indexed. When I removed the `notes` <> "" from the complex query, there is a 60% improvement (20 seconds vs 7 seconds). I'm thinking of adding an indexed `has_notes` bit field but now I have to maintain the integrity at the application level. The other is to convert the notes column to a varchar with a large enough size, then create an index.

What is the best practice for querying if a TEXT column is not empty?

🌐
Mimo
mimo.org › glossary › sql › is-not-null
SQL IS NOT NULL Condition: Syntax, Usage, and Examples
Use SQL IS NOT NULL in a WHERE clause to filter out records that contain empty or missing values in a column. ... Become a back-end developer. Learn SQL, databases, server-side programming, and APIs to build scalable applications
🌐
Devgex
devgex.com › en › article › 00002441
Complete Guide to Checking for Not Null and Not Empty String in SQL Server - DevGex
October 30, 2025 - CREATE PROCEDURE GetUserByEmail ... END · When checking if a column is neither NULL nor empty string in SQL Server, WHERE ColumnValue <> '' is recommended for its simplicity, efficiency, and readability....
🌐
SQLServerCentral
sqlservercentral.com › home › topics › 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:
🌐
SQL Team
sqlteam.com › forums › topic.asp
Select not empty on data type=text fields - SQL Server Forums
March 9, 2007 - Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers.