Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Unanswered: Separating Fields

    I have a database that I need to get information from. However, one of the fields have been used for what should just be a product name,but it has, Product Name, Size, Strength I need each of these fields to be separate field. How can I extract the data with a SQL query with each field becoming it's own they are separated by a space. Is it possible? Any ideas? I am using MYSql to query the data


    Thanks!
    Liro

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    separated by spaces? that's easy
    Code:
    SELECT SUBSTRING_INDEX(field,' ',1) AS product_name
         , SUBSTRING_INDEX(SUBSTRING_INDEX(field,' ',2),' ',-1) AS size
         , SUBSTRING_INDEX(SUBSTRING_INDEX(field,' ',3),' ',-1) AS strength
      FROM ...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    I tried this with all three lines and then one at a time and it wouldn't work.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by liro0917 View Post
    I tried this with all three lines and then one at a time and it wouldn't work.
    okay, dump the table, please, and a couple of lines of data
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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