[英]T-SQL Replace “cyrillic symbols” returns '????'
I have a function that converts CSV list to nvarchar(max) records in table. 我有一个函数将CSV列表转换为表中的nvarchar(max)记录。 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. @List是NVARCHAR(MAX),我正在使用SQL Server 2012。
Are you defining your @List
variable as nvarchar? 您是否将
@List
变量定义为nvarchar? Replace will work fine with nvarchars 替换将与nvarchars一起正常工作
declare @list nvarchar(50) = N'те,ст'
select @list
DECLARE @XML xml = N'<r><![CDATA[' + REPLACE(@List, ',', ']]></r><r><![CDATA[') + ']]></r>'
The N''
notation is used to declare Unicode string literals. N''
表示法用于声明Unicode字符串文字。 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). 如果您定义了一个变量NVARCHAR,它将自动启用Unicode(因此不需要(或者更确切地说:无法)为@variables另外声明
N
- 它是字符串文字的一部分)。
Since you get Cyrillic characters in SELECT N'тест'
, you should check where the variable @List is assigned, and what it's value is. 由于您在
SELECT N'тест'
获得了西里尔字符,因此您应该检查变量@List的分配位置以及它的值。
Not sure how your CSV parser handles Unicode characters, but the source of your problem may be 不确定CSV解析器如何处理Unicode字符,但问题的根源可能是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.