-1

I have an output like 9.23333 9.44444 separated by space in a column.

I want to separate that into two columns like 9.2333 in col a and 9.444 in col b

How can I do that?

Please help me

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Banti
  • 1
  • 2
  • 1
    Have you attempted anything yet? Also, please tag your question with the DBMS you are using (Oracle, mysql, postgresql, etc...). – gmiley Nov 09 '15 at 19:22
  • 1
    What have you tried so far and what problems have you encountered? stackoverflow isn't here to do your (home)work for you, it's to answer *specific* questions about *specific* problems. So share the code (SQL in this case) you've tried so far, what inputs you're testing against, and what it's doing with those inputs vs. what you want it to do. – blm Nov 09 '15 at 19:23
  • Possible duplicate of [How do I split a string so I can access item x?](http://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x) – JamieSee Nov 09 '15 at 19:26
  • Possible duplicate of [Split sql string into words](http://stackoverflow.com/questions/5875532/split-sql-string-into-words) – maraca Nov 09 '15 at 19:40

1 Answers1

0

you can use the below query (i split my name into 2 rows), you can find my name in bold:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.e, ' ', n.n), ' ', -1) value
  FROM (select **'jack chalouhy'** e) t CROSS JOIN 
(
   SELECT a.N + b.N * 10 + 1 n
     FROM 
    (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
   ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b
    ORDER BY n
) n
 WHERE n.n <= 1 + (LENGTH(t.e) - LENGTH(REPLACE(t.e, ' ', '')))
 ORDER BY value

goodluck

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786