Function to Clear Special Characters in SQL Server
Hello everyone,
In this article, I will try to give information about the function that clears special characters in SQL Server.
In SQL Server you may want to clear special characters in some cases.
You can easily do this using the function below.
CREATE FUNCTION fn_Ozel_Karakterleri_Temizle (@Temp VARCHAR(2000))
RETURNS VARCHAR(2000)
AS
BEGIN
DECLARE @KeepValues AS VARCHAR(50)
SET @KeepValues = '%[^A-Za-z0-9.?_,!]%'
WHILE patindex(@KeepValues, @Temp) > 0
SET @Temp = STUFF(@Temp, patindex(@KeepValues, @Temp), 1, '')
RETURN @Temp
END
--Use of Function
SELECT dbo.fn_Ozel_Karakterleri_Temizle('ssdfsdfsd**----')
When you create and run the above function, you will see a result similar to the one below.
As you can see, we have cleared the special characters.
Good luck to everyone in business and life.