rap-2-h
rap-2-h

Reputation: 32028

How to match not null + not empty?

I have to do some queries on a messy database. Some columns are filled with either null or an empty string. I can do a query like this:

select * from a where b is not null and b <> '';

But is there a shortcut for this case? (match every "not empty" value) Something like:

select * from a where b is filled;

Upvotes: 24

Views: 43027

Answers (2)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125424

Just:

where b <> ''

will do what you want as null <> '' is null and the row will not be returned

Upvotes: 60

Steve Smith
Steve Smith

Reputation: 2270

select * from a where COALESCE(b, '') <> '';

Upvotes: 3

Related Questions