24

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;
1
  • 2
    Not a duplicate. The other question is null or empty while this question is not null and not empty Commented Jan 30, 2017 at 15:18

2 Answers 2

60

Just:

where b <> ''

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

2
  • 2
    or LTRIM(b) <> '' if there's the possibility of rows with more than a single space.
    – Nick
    Commented Jul 7, 2022 at 15:54
  • invalid input syntax for type integer: "" so, if column b is INT then b <> 0 but your answer is enough correct for the Q: '...or an empty string' Commented Jul 26, 2023 at 13:01
3

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.