SQL take just the numeric values from a varchar

Here’s the example with PATINDEX:

select SUBSTRING(fieldName, PATINDEX('%[0-9]%', fieldName), LEN(fieldName))

This assumes (1) the field WILL have a numeric, (2) the numerics are all grouped together, and (3) the numerics don’t have any subsequent characters after them.

Leave a Comment