Menu ▼



Posted By :
avatarmrkraju
Total Views : 311

SQL function to remove non alphabet characters

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

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

Example:
SELECT dbo.RemoveNonAlphabetCharacters('Hello 123, How are you?')
Output:
HelloHowareyou





comments powered by Disqus


Search dotnetlearners.com