Function to Fix Turkish Character Problem in SQL Server
Hello to everyone,
In this article, I will give information about the function that fixes the Turkish character problem in SQL Server.
First of all, there are other solutions to this process. Please also research these methods before using functions.
You may experience Turkish character problems in SQL Server in some cases.
You can easily solve this problem by using the function below.
--Creating the function
CREATE FUNCTION fn_FixTurkishCharacterIssue
(
@Writing NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @Result NVARCHAR(MAX);
SET @Result = @Writing;
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'ð', N'ğ');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'ð', N'Ğ');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'Ð', N'Ğ');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'ý', N'ı');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'Ý', N'İ');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'þ', N'ş');
SET @Result = REPLACE(@Result COLLATE Latin1_General_BIN, N'Þ', N'Ş');
RETURN @Result COLLATE Turkish_CI_AS;
END;
--Using the function
SELECT dbo.fn_FixTurkishCharacterIssue(N'þýrýnga');
When you create the function and run the code, you will see a result similar to the one below.
As you can see, the Turkish character problem has been fixed.
Good luck to everyone in business and life.