Connecting Tech Pros Worldwide Forums | Help | Site Map

Parse field with underscore character

Newbie
 
Join Date: Jul 2007
Posts: 1
#1: Jul 18 '07
If i have field in table which include value such as (111_556_ _ _555_88). how can i get each part of the field by sql?

mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#2: Jul 18 '07

re: Parse field with underscore character


If the pattern is the same use only SUBSTRING() as i did below
Expand|Select|Wrap|Line Numbers
  1. SELECT SUBSTRING('111_556_ _ _555_88', 1,3)  AS first_part,
  2. SUBSTRING('111_556_ _ _555_88', 5,3) AS second_part
But if the digits are of variable length between underscores then use LOCATE() with SUBSTRING(). List of all mysql string functions can be found here http://dev.mysql.com/doc/refman/5.0/...functions.html.
Reply