Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    1

    Unanswered: Split one Field into several fields

    Hello,

    here a part of the table:

    id = 0000000006
    actiontype = 1
    datafield = 90000,Manuel

    i wrote following script, to split datafield values in two fields:

    Select `actiontype`,
    case when instr(`datafield`, ',') > 0
    then substr(`datafield`, 1, instr(`datafield`, ',')-1)
    else ' '
    end as user_id
    ,
    case when instr(`datafield`, ',') > 0 and instr(`datafield`, ',') < length(`datafield`)
    then substr(`datafield`, instr(`datafield`, ',') + 1)
    else `datafield`
    end as first_name
    from `interfacetbl`
    WHERE actiontype = 1

    Now, i would like to know how to split field values in more then two fields,
    for example:


    id = 0000000006
    actiontype = 1
    datafield = 90000,Manuel,Weis,printcarrier.com

    The four fields:

    user_id = 90000
    first_name = Manuel
    last_name = Weis
    company = printcarrier.com

    How to realize?
    Last edited by jagr2510; 05-09-11 at 10:21.

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Hi, it should be mentioned that if you need to perform this type of operation then you should look more closely at your data model. As an exercise I have put together some code and explanation on how this can be done here
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •