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.

Function to Clear Special Characters in SQL Server

As you can see, we have cleared the special characters.

Good luck to everyone in business and life.

66 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!