Saturday, 24 September 2016

SQL function to remove non alphabet characters

SQL function to remove non alphabet characters

Description:

In this example we explain that how to remove non alphabet character from string in SQL Server.or fetch the string without non alphabet character or removing non alphabet character from string using SQL Server function.

Here we create one SQL Server user defined function that will return string or text with removing non alphabet character in SQL Server.here we simply input the value to SQL Server function and it will returns the string or value with removing non alphabet character.

So below is the SQL Server user defined function that will remove non alphabet characters from the given input value.
Function:

CREATE Function [dbo].[RemoveNonAlphabetCharactersFromInputedValue](@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 

--Execute Query After Create Above Function


SELECT dbo.[RemoveNonAlphabetCharactersFromInputedValue]('Hello kirit,88& 123, How are you?')
This entry was posted in :

0 comments:

Post a Comment