SQL function to remove non numeric characters

Below SQL function will remove the non numeric characters from the given input value.

CREATE Function [dbo].[RemoveNonNumaricCharacters](@Val VarChar(1000)) Returns VarChar(1000) AS Begin Declare @RegExp as varchar(50) Set @RegExp = '%[^0-9]%' While PatIndex(@RegExp, @Val) > 0 Set @Val = Stuff(@Val, PatIndex(@RegExp, @Val), 1, '') Return @Val End

Example:
SELECT dbo.RemoveNonNumaricCharacters('Hello 123')
Output:
123