SQL using case to Identify blanks vs NULLs

I had a strange issue driving me nuts today. I had data with null values and could use isNull to capture most of them and assign a new value to the field. However about 10 records would not accept the isnull logic. Finally after about 2 hours of beating the keyboard to death I finally realized the field was not null but contained blanks. So here is the code that can help if you run into this same situation.


select CASE _fieldname_
When NULL Then 'missing'
When '' Then 'spaces'
Else _fieldname_
END as _fieldname_
from tablename

* Replace the _fieldname_ with your fieldname containing blanks and nulls

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Snippets, SQL and tagged , , , . Bookmark the permalink.