Reputation: 4685
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.
Upvotes: 1
Views: 332
Reputation: 37398
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
Upvotes: 1