Parse field with underscore character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samirn
    New Member
    • Jul 2007
    • 1

    #1

    Parse field with underscore character

    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
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    If the pattern is the same use only SUBSTRING() as i did below
    [CODE=mysql]SELECT SUBSTRING('111_ 556_ _ _555_88', 1,3) AS first_part,
    SUBSTRING('111_ 556_ _ _555_88', 5,3) AS second_part[/CODE]

    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.

    Comment

    Working...