Skip to content Skip to sidebar Skip to footer

How To Use Null Or Empty String In Sql

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

Solution 1:

Select*FromTableWhere (col isnullor col ='')

Or

Select*FromTableWhere IsNull(col, '') =''

Solution 2:

If you need it in SELECT section can use like this.

SELECT ct.ID, 
       ISNULL(NULLIF(ct.LaunchDate, ''), null) [LaunchDate]
FROM   [dbo].[CustomerTable] ct

You can replace the null with your substitution value.

Solution 3:

You can simply do this:

SELECT*FROM   yourTable
WHERE  yourColumn ISNULLOR yourColumn =''

Solution 4:

SELECT*FROM   TableName
WHERE  columnNAme ISNULLOR 
       LTRIM(RTRIM(columnName)) =''

Solution 5:

To find rows where col is NULL, empty string or whitespace (spaces, tabs):

SELECT*FROMtableWHERE ISNULL(LTRIM(RTRIM(col)),'')=''

To find rows where col is NOT NULL, empty string or whitespace (spaces, tabs):

SELECT*FROMtableWHERE ISNULL(LTRIM(RTRIM(col)),'')<>''

Post a Comment for "How To Use Null Or Empty String In Sql"