Link to home
Start Free TrialLog in
Avatar of Peet Pienaar
Peet Pienaar

asked on

Return Alpha values from a ID field

I need to pull out only the alpha characters from an ID file not numeric values, but this returns the numeric values as well

Please assist have found the following for DB2
SELECT CIN, NATIONAL_ID,FNAME,MNAME,LNAME1,LNAME2
FROM    Prodmgr.T_Consumer
WHERE   CIN  NOT IN  (SELECT CIN FROM Prodmgr.T_REPORT_CONSUMER)
and NATIONAL_ID not like '%?%?'
and ( National_ID not in '%A%'or National_ID LIKE '%B%'or National_ID LIKE '%C%'
or National_ID LIKE '%D%'or National_ID LIKE '%E%'or National_ID LIKE '%F%'
or National_ID LIKE '%G%'or National_ID LIKE '%H%'or National_ID LIKE '%I%'
or National_ID LIKE '%J%'or National_ID LIKE '%K%'or National_ID LIKE '%L%'
or National_ID LIKE '%M%'or National_ID LIKE '%N%'or National_ID LIKE '%O%'
or National_ID LIKE '%P%'or National_ID LIKE '%R%'or National_ID LIKE '%S%'
or National_ID LIKE '%T%'or National_ID LIKE '%U%'or National_ID LIKE '%V%'
or National_ID LIKE '%w%'or National_ID LIKE '%X%'or National_ID LIKE '%Y%'
or National_ID LIKE '%Z%')
ORDER by National_ID DESC;
Avatar of Manju
Manju
Flag of India image

While there are many ways to achieve this, including creating a function, why dont we use simple replace function?

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(<your Column or Variable>,'1',''),'2',''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9',''),'0','')
Do you have a pattern, I.e. The non numeric values only appear in a specific locations?
What is the DB ms SQL or db2?
What are you using to extract and display this informations?i.e. Can the masking/extraction/changes be done by the rendering process asp, php, etc.
I.e get the entire ID from the DB and then process the results in the event the rendering software includes straight forward tools to extract only the non-numeric values.
Avatar of Peet Pienaar
Peet Pienaar

ASKER

HI Manju

DB2 does not seem to like the replace function
@ Arnold
There is no patterns, the placings is random
Not sure if the masking etc can work ?  We using DB2  to extract the data
with db2...,

how about below sample

...
where
columna = replace(columna, ' ', '?')
and
translate(columna, ' ',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|| Lcase('ABCDEFGHIJKLMNOPQRSTUVWXYZ') ) = ' '
Hi there Manju

That is working, thank you so much, is it correct to bring back full names, as i know in some rows we do have space and then alpha characters

Thank you

Kind regards
ASKER CERTIFIED SOLUTION
Avatar of Manju
Manju
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial