Connecting Tech Pros Worldwide Help | Site Map

Find empty fields

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#1: Aug 18 '09
How can empty fields be detected.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM products WHERE 
  2. description IS EMPTY
The field may be NULL
or just empty and I suppose even space characters.
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 785
#2: Aug 19 '09

re: Find empty fields


Expand|Select|Wrap|Line Numbers
  1. SELECT * 
  2. FROM products 
  3. WHERE  description IS null OR rtrim(description)=''
  4.  
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#3: Aug 19 '09

re: Find empty fields


Thanks Delerna
I figured as much, I do something similar in MySql.
Although I once had a regex that achieved this.

But it may need to be RTRIM(LTRIM(description))=''
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#4: Aug 20 '09

re: Find empty fields


also...

Expand|Select|Wrap|Line Numbers
  1. WHERE isnull(rtrim(ltrim(description)),'') = ''
  2.  
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#5: Aug 20 '09

re: Find empty fields


Expand|Select|Wrap|Line Numbers
  1. WHERE isnull(rtrim(ltrim(description)),'') = '' 
I like that ck9663, although I can't quite see how it works.
It looks like a COALESCE should be there
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#6: Aug 20 '09

re: Find empty fields


Got it. isnull() function rather than IS NULL
Reply