Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Wed, 13 Feb 2013 @ 19:51:12 GMT

  <Prev Next>   <<First <Prev

Subj:   Re: Need to filter Numeric value from Alphanumeric string
From:   de Wet, Johannes M

Your options are probably either to use a UDF/TRANSLATE function to replace non-numeric values with empty strings, resulting in a numeric-only result (we've had good success with that in the past, using a 'TRANSLATE' function), or hard-code the translation as shown below. Unfortunately, if the string is long you might end up with a long CASE statement...

         'str55555ingd4w5i6th8digit' AS MyString
         ,CASE WHEN SUBSTR(MyString,1,1) BETWEEN 0 and 9 THEN
     SUBSTR(MyString,1,1) ELSE '' END
        ||CASE WHEN SUBSTR(MyString,2,1) BETWEEN 0 and 9 THEN
     SUBSTR(MyString,2,1) ELSE '' END
        ||CASE WHEN SUBSTR(MyString,3,1) BETWEEN 0 and 9 THEN
     SUBSTR(MyString,3,1) ELSE '' END
        ||CASE WHEN SUBSTR(MyString,4,1) BETWEEN 0 and 9 THEN
     SUBSTR(MyString,4,1) ELSE '' END
        ||CASE WHEN SUBSTR(MyString,5,1) BETWEEN 0 and 9 THEN
     SUBSTR(MyString,5,1) ELSE '' END


Johannes de Wet
Data and Information Services

  <Prev Next>   <<First <Prev
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 24 Jul 2020