Tuesday, September 21, 2010

How to search for blank cells in SQL

Suppose there are some blank cells  in column [text] of the [table]. How can you find them in SQL2005?
Let's see what are not working.
  • SELECT * FROM [table] WHERE [text] IS NULL
  • SELECT * FROM [table] WHERE [text] = ''
  • SELECT * FROM [table] WHERE LEN([text]) = 0
So what is working.
  • SELECT * FROM [table] WHERE LEN([text]) = 1
This essentially implies that LEN() counts the string null terminator as one character. What a broken definition of string length!

No comments:

Post a Comment