Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Search for first substring in string with condition - response (3) by dnoeth

$
0
0

Hi Peter,
based on the data you provided this should work (i just use POSITION instead of INDEX):

SELECT Seq, Str,
   CASE
      WHEN POSITION('a' IN Str) = 0
        OR POSITION('a' IN Str) > POSITION('b' IN Str)
        OR Str NOT LIKE '%a%b%a%' 
      THEN POSITION('b' IN Str)
      ELSE POSITION('b' IN SUBSTR(Str, POSITION('b' IN Str) + 1)) + POSITION('b' IN Str)
   END
FROM T1

Of course your specs are a bit vague :-)
Are following cases possible and what's the expected result?
'aba--aba---b'
'abba---b'
'a-ab-a---b'

This might require recursion or maybe a regular expression in TD14 using REGEXP_INST.

 

Dieter


Viewing all articles
Browse latest Browse all 14773

Trending Articles