0

I have created a user defined function that strips input text from HTML tags, but found that it also destroys Arabic text for some reason.

I thought: maybe the function's logic causes the text to be converted to VARCHAR somewhere, so I made the function very simple.. It takes an NVARCHAR and returns it to the caller.. Here is the function:

CREATE FUNCTION [dbo].[udf_test] (@string NVARCHAR(MAX))
RETURNS NVARCHAR(MAX) AS
begin
  return @string
end

then I made a small test:

select dbo.udf_test('إختبار اللغة العربية Testing Arabic ');

the output is:

?????? ????? ??????? Testing Arabic 

The output is fine if I do this:

select 'إختبار اللغة العربية Testing Arabic ';

Why does that happen?

Ahmad
  • 12,336
  • 6
  • 48
  • 88

1 Answers1

2

You need to explicitly specify the string a NVARCHAR type. Adding an N before the string should solve the problem

select dbo.udf_test(N'إختبار اللغة العربية Testing Arabic ');
Alex
  • 21,273
  • 10
  • 61
  • 73