t sql return on letters only 1

t sql return on letters only

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

    Declare @KeepValues as varchar(50)
    Set @KeepValues = '%[^a-z]%'
    While PatIndex(@KeepValues, @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')

    Return @Temp
End

Here is what the above code is Doing:
1. It creates a function called RemoveNonAlphaCharacters.
2. It takes a string as an input parameter.
3. It returns a string.
4. It declares a variable called @KeepValues.
5. It sets @KeepValues to a string that contains a regular expression.
6. It loops through the input string and replaces any character that is not a letter with an empty string.
7. It returns the modified string.

Similar Posts