Question : SQL - Trim letters out of a field where the length is unknown

I have a column of policy numbers, some numbers and some with numbers and letters at the end.  They vary in length.  I need to trim off the letters on the end and make them an 8 character field, with padded zeroes if necessary.

Examples:  
4253700         should be  04234700
00502693CA   should be  00502693
000523015     should be  00523015

In SAS, I use a compress function:  input(compress(c_pol,,'DK') to help do this, but I don't know what to use in SQL.  Help!  Thank you.

Answer : SQL - Trim letters out of a field where the length is unknown

I'm not sure what is your complete code, but from what you mentioned in your last post, the logic is incorrect. It should be something like this

CASE WHEN udf_isnumeric(c_pol) = 1 THEN substr(c_pol, 1, 8)  ELSE  substring('0000' + cast(c_pol as integer) from character_length('0000' + cast(c_pol as integer)) - 8 for character_length('0000' + cast(c_pol as integer)))

Random Solutions  
 
programming4us programming4us