Script to Strip Non Numeric Characters from string

Below sample script strips (removes) non numeric Characters from string (varchar)

[sql]
DECLARE @VARCHARString VARCHAR(8000)

SET @VARCHARString = ‘000012W`”ASDASDS3A@!#@!#_)+)_4)’

SELECT @VARCHARString

–Remove non numeric charecters from the varchar variable
WHILE PATINDEX(‘%[^0-9]%’, @VARCHARString) > 0
SET @VARCHARString = STUFF(@VARCHARString, PATINDEX(‘%[^0-9]%’, @VARCHARString), 1, ”)

SELECT @VARCHARString
[/sql]

Leave a Reply

Your email address will not be published. Required fields are marked *