If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How To Find Fields Containing One String Character?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-12, 11:02
rockdave35 rockdave35 is offline
Registered User
 
Join Date: Jan 2009
Posts: 46
How To Find Fields Containing One String Character?

Hey guys,

I am creating a query that will return all member names where their first name contains a single character.

I can't find any db2 functions that will work for me. I can accomplish this in SQL with "where DATA_LENGTH(FNAME) = 1", but I can't find a DB2 equivalent to this function.

The string functions don't seem to work because they would be looking for specific values. Can anyone help?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 07-19-12, 11:35
rockdave35 rockdave35 is offline
Registered User
 
Join Date: Jan 2009
Posts: 46
I just found the solution:

where LENGTH(RTRIM(NAME)) = 1
Reply With Quote
  #3 (permalink)  
Old 07-19-12, 12:52
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,721
At least up to the SQL standard 2003, DATA_LENGTH is not a standardized function. So for more portable code, you shouldn't rely on it in other database systems either.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 07-19-12, 15:34
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 155
where length(replace(FNAME,' ','') = 1
or
where length(strip(FNAME,B,' ') = 1

will preclude your overlooking FNAMEs that start with a space and then a character.
__________________
Dick Brenholtz, Ami in Deutschland

Last edited by dbzTHEdinosaur; 07-19-12 at 15:39. Reason: added strip scalar function
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On