CREATE FUNCTION [dbo].[RemoveSpecialCharacters](@StrValue NVARCHAR(4000))
RETURNS NVARCHAR(4000)
AS
BEGIN
Declare @KeepValues as varchar(50)
SET @StrValue = LTRIM(RTRIM(@StrValue))
SET @KeepValues = '%[^a-z0-9]%'
WHILE PATINDEX(@KeepValues, @StrValue) > 0
SET @StrValue = STUFF(@StrValue, PATINDEX(@KeepValues, @StrValue), 1, '')
Return @StrValue
END
Result:
SELECT DBO.RemoveSpecialCharacters('Welcome %To $Axil - 007')
WelcomeToAxil007
No comments:
Post a Comment