Monday 29 May 2017

Return only Rows that have an empty field in SQL Server.

Only return rows that have an empty field?
Description:

In this example we explain that how to return only rows that have an empty field in SQL Server. Or SQL Query to return only rows that have an empty fields. Or sql query to return all the rows that have null or empty fields. There are many question raised as per different user like getting all Records where particular fields is non empty or select all record with NO NULL value in table or getting all records where particular column is empty in SQL Server.


Suppose I have one SQL Table have one fields like FirstName can be empty or null in database now I want to display all the record with FirstName is not null or empty means FirstName must have some value or text. so below is the query to fetch rows from table with not empty.

Query:

SELECT * FROM MyTable WHERE LTRIM(RTRIM(ISNULL(MyField, ''))) = ''
SELECT * 
  FROM MyTable 
 WHERE IIF(MyField = ' ', NULL, MyField) IS NULL;


This entry was posted in :

0 comments:

Post a Comment