gotqn
gotqn

Reputation: 43636

T-SQL Replace "cyrillic symbols" returns '????'

I have a function that converts CSV list to nvarchar(max) records in table. I have noticed it is not working with cyrillic and the problem is this replace here:

DECLARE @XML xml = N'<r><![CDATA[' + REPLACE(@List, ',', ']]></r><r><![CDATA[') + ']]></r>'

How to make the replace to work with cyrillic symbols? For example 'тест'.

@List is NVARCHAR(MAX) and I am using SQL Server 2012.

Upvotes: 0

Views: 2450

Answers (2)

devio
devio

Reputation: 37215

The N'' notation is used to declare Unicode string literals. If you define a variable NVARCHAR, it is automatically Unicode-enabled (so there is no need (or rather: no way) to additionally declare the N for @variables - it is part of the string literal).

Since you get Cyrillic characters in SELECT N'тест', you should check where the variable @List is assigned, and what it's value is.

Not sure how your CSV parser handles Unicode characters, but the source of your problem may be

  • not handling file encodings
  • assigning to a VARCHAR column or variable before assigning to @List

Upvotes: 1

podiluska
podiluska

Reputation: 51494

Are you defining your @List variable as nvarchar? Replace will work fine with nvarchars

declare @list nvarchar(50) = N'те,ст'
select @list
DECLARE @XML xml = N'<r><![CDATA[' + REPLACE(@List, ',', ']]></r><r><![CDATA[') + ']]></r>'

Upvotes: 1

Related Questions