1

Is there an efficient way using sql server 2005 to remove all characters in a string like this which are not numbers?

TEXT T EXT TEXT 2345 TEXT SDTE

I was thinking there might be a way to combine the replace statement with a regular expression.

some_bloody_fool
  • 4,605
  • 14
  • 37
  • 46
  • possible duplicate of [How to strip all non-alphabetic characters from string in SQL Server?](http://stackoverflow.com/questions/1007697/how-to-strip-all-non-alphabetic-characters-from-string-in-sql-server) – Michael Fredrickson Feb 28 '12 at 17:01

1 Answers1

1

Here is the answer from the related question, with the slight change needed to remove non-numbers as opposed to non-alphas:

Create Function [dbo].[RemoveNonNumericCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

    While PatIndex('%[^0-9]%', @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex('%[^0-9]%', @Temp), 1, '')

    Return @Temp
End
Community
  • 1
  • 1
Michael Fredrickson
  • 36,839
  • 5
  • 92
  • 109