[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • 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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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