¿Esto funciona más rápido para ti? (Utilicé mi intercalación de SQL_Latin1_General_CP1_CS_AS, es posible que desee cambiar eso).
ALTER FUNCTION [dbo].[ArabicToString] (@inString VARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @MappingCharacters TABLE
(
InputCharacter NCHAR(1) COLLATE SQL_Latin1_General_CP1_CS_AS PRIMARY KEY,
OutputChar NCHAR(1)
)
INSERT @MappingCharacters
VALUES
('A', 'ء')
,('B', 'آ')
,('C', 'أ')
,('D', 'ؤ')
,('E', 'إ')
,('F', 'ئ')
,('G', 'ا')
,('H', 'ب')
,('I', 'ة')
,('J', 'ت')
,('K', 'ث')
,('L', 'ج')
,('M', 'ح')
,('N', 'خ')
,('O', 'د')
,('P', 'ذ')
,('Q', 'ر')
,('R', 'ز')
,('S', 'س')
,('T', 'ش')
,('U', 'ص')
,('V', 'ض')
,('W', 'ط')
,('X', 'ظ')
,('Y', 'ع')
,('Z', 'غ')
,('a', 'ف')
,('b', 'ق')
,('c', 'ك')
,('d', 'ل')
,('e', 'م')
,('f', 'ن')
,('g', 'ه')
,('h', 'و')
,('i', 'ى')
,('j', 'ي')
,('v', 'ـ')
,('1', '١')
,('2', '٢')
,('3', '٣')
,('4', '٤')
,('5', '٥')
,('6', '٦')
,('7', '٧')
,('8', '٨')
,('9', '٩')
,('0', '٠')
,('/', '\')
DECLARE @Result NVARCHAR(MAX) = ''
, @Position INT = 1
, @StrLength INT = DATALENGTH(@inString)
DECLARE @Vchar char(1), @NextChar NCHAR(1)
SET @VChar = SUBSTRING(@inString, @Position, 1)
IF ASCII(@Vchar) > 189 and ASCII(@Vchar) < 255
RETURN Rtrim(Ltrim(@inString))
WHILE (@Position <= @StrLength) -- leave loop if bad character found
BEGIN
-- Reset holders
SET @NextChar = SUBSTRING(@inString, @Position, 1)
SET @Result = @Result + ISNULL((SELECT OutputChar FROM @MappingCharacters MC WHERE InputCharacter = @NextChar COLLATE SQL_Latin1_General_CP1_CS_AS), @NextChar)
-- Add one to position
SET @Position= @Position + 1
END
RETURN Rtrim(Ltrim(@Result))
END
GO
Es muy similar, pero espero que en lugar de una serie muy grande de else if
controles, SQL Server funcionará mejor cuando trabaje con un conjunto. No estoy seguro de si esto funcionaría mejor si @MappingCharacters
era una mesa real o no.