Home Page for the TeradataForum
 

Archives of the TeradataForum

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


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


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...

     SELECT
         '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

     etc..

Johannes de Wet
Data and Information Services
Unum



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