Script to Strip Non Numeric Characters from string

Posted on : 24-04-2012 | By : Devi Prasad | In : SQLServerPedia Syndication, T-SQL Code Examples

Share:

0


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

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
(Visited 637 times, 1 visits today)



References : Devi Prasad (sqlserverlearner.com)

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.


Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.




Write a comment



Tags: ,