I have a database build using SQL Server 2019, inside there is a function called handle_letters
performs some processing using T-SQL REPLACE
function as follows:
create or alter function handle_letters(@txt as nvarchar(50))
returns nvarchar(50)
begin
set @txt = replace(@txt, N'أ', N'ا');
set @txt = replace(@txt, N'إ', N'ا');
set @txt = replace(@txt, N'ى', N'ا');
set @txt = replace(@txt, N'آ', N'ا');
set @txt = replace(@txt, N'ؤ', N'ء');
set @txt = replace(@txt, N'ـ', N'');
set @txt = replace(@txt, N'ة', N'ه')
set @txt = replace(@txt, N'ُ', N'');
set @txt = replace(@txt, N'َ', N'');
set @txt = replace(@txt, N'ً', N'');
set @txt = replace(@txt, N'ٌ', N'');
set @txt = replace(@txt, N'ِ', N'');
set @txt = replace(@txt, N'ٍ', N'');
set @txt = replace(@txt, N'ّ', N'');
set @txt = replace(@txt, N'ئ', N'ء');
return replace(@txt, N'عبدا', N'عبد ا');
end
The problem appears when working the letter Taa Marbouta "ة" as I need to return it to its linguistic origin as Haa "ه" (similar pronunciation to the English letter H) however, SQL server deals with the Taa Marbouta as same as Taa Mabsouta "ت" (similar pronunciation to the English letter T) even though they are 2 different letters in the Arabic language.
The following is a correct execution of the function:
select dbo.handle_letters(N'كرة')
= "كره"
While the following is incorrect result:
select dbo.handle_letters(N'كرات')
="كراه" which is incorrect as it should remain as it is "كرات"
The database collation is SQL_Latin1_General_CP1_CI_AS
which I believe is the problem but I could be mistaken
Also the SQL Server runs on a Linux machine, meaning I cannot use DotNet to create a custom function in C# to handle this process. as indicated by this Github page