How to strip all non-alphabetic characters from string in SQL Server? SQL Server Interview Question

SQL Server Interview Question: How to strip all non-alphabetic characters from string in SQL Server?
You can create a function for this
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

And Call this function as
Select dbo.RemoveNonAlphaCharacters('ewrqrewr43gf34gf5345jgh454353hf')
Click here for more than 300 Sql server Interview questions

Comments

Archive

Contact Form

Send