• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

informix extract part of string

I have a table

table1
ID --- Note
1 ----- 0240231123 merged to ID 02427299912              
2 ----- 0242296335 merged to ID P125903                

I would like to extract only the first value in the note using a SQL query:

ID --- value ----------------- Note
1 ----- 0240231123 ---- 0240231123 merged to ID 02427299912              
2 ----- 97996536 ---------97996536 merged to ID P125903    

not sure what the sql query is?
0
JCTDD
Asked:
JCTDD
1 Solution
 
jhp333Commented:
If you're using Informix 11.7, you can use CHARINDEX( ) or INSTR( ) function together with SUBSTR( ).
But it seems those two are newly introduced in Informix 11.7
If you have an older version, you need to create a UDR in C or java language...

Or you can try something like this:

SELECT ID,
  CASE
    WHEN note[1] = ' ' THEN ''
    WHEN note[2] = ' ' THEN note[1]
    WHEN note[3] = ' ' THEN note[1,2]
    WHEN note[4] = ' ' THEN note[1,3]
    WHEN note[5] = ' ' THEN note[1,4]
    .
    .
    .
  END,
  note
FROM your_table


Yes, it's kind of dumb, but it should work.
0
 
awking00Commented:
What version of Informix are you using?
0
 
JCTDDAuthor Commented:
using informix version 10
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now