19

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;
rap-2-h
  • 26,857
  • 31
  • 150
  • 246

2 Answers2

40

Just:

where b <> ''

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

Clodoaldo Neto
  • 108,856
  • 25
  • 211
  • 247
2

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

Steve Smith
  • 2,141
  • 2
  • 15
  • 22