4

I have a very simple task which is turning out to be impossible. I have a column that has strings but also has blanks where it supposed to be a word (those are not NULLs they are just empty strings). For example:

LastName1,
EmptyRow,
LastName2,
EmptyRow,
EmptyRow,
LastName3...

Since empty rows are not NULLs, IS NOT NULL function is not working.

In the end result, I just need to filter out all rows that actually have values in them and get rid of all the empty rows. Can someone please give a suggestion?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Agnieshka
  • 41
  • 1
  • 1
  • 3

3 Answers3

10

You can filter out these records by applying LENGTH function to it.

WHERE LENGTH(TRIM(COL_NAME)) > 0
Shantanu Kher
  • 1,014
  • 1
  • 8
  • 14
2

If there is a mix of single spaces, no spaces and nulls, I uses something like this

WHERE COALESCE(TRIM( lastname ), '') <> ''
JayRizzo
  • 3,234
  • 3
  • 33
  • 49
Mike Gohl
  • 627
  • 4
  • 7
0

You need to know what "empty" row means. Most likely an empty string:

where lastname > ''

If you need to be sure that there is at least one letter you can use:

where lastname regexp '[a-zA-Z]'

or:

where lastname regexp '[[:alpha:]]'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786