This will select all rows where some_col is NULL or '' (empty string)

SELECT * FROM table WHERE some_col IS NULL OR some_col = '';
Answer from maฤek on Stack Overflow
๐ŸŒ
Coginiti
coginiti.co โ€บ home โ€บ beginner โ€บ sql is null
What is the IS NULL Operator in SQL? - Coginiti
September 25, 2023 - The SQL IS NULL is an operator that tests for NULL (or empty) values in a column. It is a common requirement to search for empty spaces in a database, as these values indicate missing or unknown data.
Discussions

Counting rows where ALL columns are either null or empty in the row?
You might be able to use a combination of NULLIF and COALESCE. On the assumption you want to count null values and blank values, check to see if you get a NULL value using: COALESCE(NULLIF(col1,''),NULLIF(col2,''), etc) The NULLIF should check each column and return NULL if the string is blank. Then the COALESCE should return the first non-NULL value ... you can use ISNULL to check if THAT value is NULL, and if so, count it. There may be a better way to actually write this than what I have above, but you shouldn't need a ton of AND/OR statements. I suspect someone with better SQL-fu than I can give a better example. More on reddit.com
๐ŸŒ r/SQLServer
23
3
September 26, 2024
Check for null or empty values and return 0 โ€“ SQLServerCentral Forums
Check for null or empty values and return 0 Forum โ€“ Learn more on SQLServerCentral More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
March 13, 2014
sql server - Test if any columns are NULL - Database Administrators Stack Exchange
I'm trying to figure out an easy query I can do to test if a large table has a list of entries that has at least ONE blank (NULL / empty) value in ANY column. I need something like SELECT * FROM ... More on dba.stackexchange.com
๐ŸŒ dba.stackexchange.com
March 12, 2012
Check the Variable is Empty or Null โ€“ SQLServerCentral Forums
Check the Variable is Empty or Null Forum โ€“ Learn more on SQLServerCentral More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
September 9, 2014
๐ŸŒ
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 - If we check the below query you can understand this as this column has EMPTY ('') and SPACES (' ') Select * from StudentsInfo WHERE Remarks IS NOT NULL
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
SELECT column_names FROM table_name ... a selection from the Customers table used in the examples: The IS NULL operator is used to test for empty values (NULL values)....
๐ŸŒ
Hightouch
hightouch.com โ€บ sql-dictionary โ€บ sql-is-null
SQL IS NULL - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - You would use the SQL IS NULL operator when you need to filter data from a table based on whether a column's value is NULL. This is useful when you want to retrieve records that lack data or records that have not been assigned a value for a ...
๐ŸŒ
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 - MS SQL provides a function ISNULL to check for null values: SELECT id, name FROM Department WHERE ISNULL(code, '') = '' OR TRIM(code) = ''; The ISNULL function in MS SQL takes two arguments: the first is a value or column name, and the second ...
๐ŸŒ
ASPSnippets
aspsnippets.com โ€บ questions โ€บ 125379 โ€บ Check-Column-value-is-Null-or-Empty-Blank-in-SQL-Server-using-Case-Statement
Check Column value is Null or Empty Blank in SQL Server using Case Statement
March 17, 2022 - CREATE TABLE [#Preparedataconvert] ( [Days] VARCHAR(10), [Class] VARCHAR(5), [One] VARCHAR(5) ) INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S1', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S1', '') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S2', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S2', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S1', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S3', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S2', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S1', 'SULK') INSERT INTO [#Preparedataconvert] VALUES ('Tuesday', 'S1', 'SULK') SELECT [Days],[Class],(CASE WHEN [One] IS NULL OR [One] <> '' THEN 'Empty' ELSE 'Ok' END) AS [One] FROM #Preparedataconvert WHERE [days]='Tuesday' DROP TABLE #Preparedataconvert
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/sqlserver โ€บ counting rows where all columns are either null or empty in the row?
r/SQLServer on Reddit: Counting rows where ALL columns are either null or empty in the row?
September 26, 2024 -

I'd rather not write a bunch of AND clauses, so is there a quick, efficient way to do this?

I'm importing some data with 10 fields into a SQL Server from a CSV file. Occasionally this file has null/empty values across all the cells/columns.

What I'd like to do is just write one relatively short sql statement to simply count (at first) all these rows. I'd rather do it without doing something like:

...and (column1 is null or column1 = '')
...and (column2 is null or column2 = '')

etc...

Is there a good way to do this, or am I stuck with the above?

๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_check.asp
SQL CHECK Constraint
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row. The following SQL creates a CHECK constraint on the "Age" column when the "Persons" table is created. The CHECK constraint ensures that the age of a person must be 18, or older: ... CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, CHECK (Age>=18) );
๐ŸŒ
W3Schools
w3schools.com โ€บ mysql โ€บ mysql_null_values.asp
MySQL NULL Values - IS NULL and IS NOT NULL
SELECT column_names FROM table_name WHERE column_name IS NOT NULL; Below is a selection from the "Customers" table in the Northwind sample database: The IS NULL operator is used to test for empty values (NULL values).
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ forums โ€บ topic โ€บ check-for-null-or-empty-values-and-return-0
Check for null or empty values and return 0 โ€“ SQLServerCentral Forums
March 13, 2014 - If you want to return a NULL instead of a certain value, i.e. empty string, you can use NULLIF. Example: nullif(ltrim(rtrim([Original])),'') AS [Originals], Does that help? If you need more help please read the article in my signature on how to post questions on the forum and please provide ...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-check-if-a-column-is-blank-in-SQL
How to check if a column is blank in SQL - Quora
Answer (1 of 3): SELECT * FROM table_name WHERE column_name IS NULL; Or, SELECT * FROM table_name WHERE column_name IS NULL AND column_name LIKE 'โ€โ€; (Note: put begining and ending quotes without any text/ space in 2nd Query.
๐ŸŒ
Darling Data
erikdarling.com โ€บ home โ€บ blog โ€บ the right way to check for nulls in sql server queries
The Right Way To Check For NULLs In SQL Server Queries | Darling Data
May 16, 2022 - I like to make sure a column returned from a select doesnโ€™t have a NULL value if it is a nullable column when the query is in an application. Much easier to handle this with a ISNULL(columnname,โ€) AS NoErrorBombsHere than to have to add error handling code throughout my application to handle NULL values. Yeah, itโ€™s a lot different in the select list than in the where clause (unless you have nested selects and filter on the expression). This is a great article about null.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ mysql โ€บ how-to-check-a-column-is-empty-or-null-in-mysql
How to Check a Column is Empty or Null in MySQL? - GeeksforGeeks
February 2, 2024 - To ascertain if a column is empty or null in SQL, use COALESCE(column, '') or column IS NULL OR column = ''. These queries fetch rows where the specified column contains an empty string or null value, ensuring comprehensive coverage of both ...
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_notnull.asp
SQL NOT NULL Constraint
This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field. The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values when the "Persons" table is created: CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int ); To create a NOT NULL constraint on the "Age" column when the "Persons" table is already created, use the following SQL: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]
๐ŸŒ
SQL Shack
sqlshack.com โ€บ working-with-sql-null-values
Working with SQL NULL values
May 19, 2021 - ISNULL(): The ISNULL() function takes two parameters and it enables us to replace NULL values with a specified value. The expression parameter indicates the expression which we want to check NULL values.
๐ŸŒ
Studytonight
studytonight.com โ€บ post โ€บ how-to-check-for-null-value-in-sql-where-clause-in-mysql
How to check for NULL value in SQL WHERE clause in MySQL - Studytonight
June 6, 2023 - ... You can also use IS NULL operator with multiple columns in the WHERE clause by using AND. ... If you want to check if the value in a column is not equal to NULL then you can use IS NOT NULL operator.
๐ŸŒ
Neon
neon.com โ€บ postgresql โ€บ postgresql-tutorial โ€บ postgresql-is-null
PostgreSQL IS NULL
The IS NOT NULL operator returns true if the value is not NULL or false otherwise. To learn how to deal with NULL in sorting, check out the ORDER BY tutorial. PostgreSQL offers some useful functions to handle NULL effectively such as NULLIF, ISNULL, and COALESCE. To ensure that a column does not contain NULL, you use the NOT NULL constraint. Weโ€™ll use the address table from the sample database: Please note that the psql program displays NULL as an empty string by default.
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ forums โ€บ topic โ€บ check-the-variable-is-empty-or-null
Check the Variable is Empty or Null โ€“ SQLServerCentral Forums
September 9, 2014 - There are some values "lower than" empty string/space. Unfortunately there is no way of distinguishing between an unknown value or a missing value in standard sql, hence the NULL. ... Please don't do this... It's one of the things that drove me crazy with c programmers - the incessant urge ...