选择查询给出输出为 ???????????不同语言的文字 [英] Select Query giving output as ??????????? with different language text

查看:26
本文介绍了选择查询给出输出为 ???????????不同语言的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个查询给我 ????????作为输出.

Why is this query giving me ???????? as output.

 Declare     @Search    NVARCHAR(MAX) = 'اختبار كتاب اللغة العربية'
 SET @Search = N''+ @Search
 select   @Search

这个工作正常的地方:-

Where as this one works fine :-

 Declare     @Search    NVARCHAR(MAX) = N'اختبار كتاب اللغة العربية'
 select   @Search 

我想让我的查询动态化.有没有其他办法可以做到?

I want to make my query dynamic. Is there any other way I can do it?

动态,我可以在@Search 参数中传递任何内容.我有一个 .NET 应用程序,我将在其中传递要在 @Search 参数中搜索的字符串,该参数可以是英语或阿拉伯语.

Dynamic in the sence I can pass anything in the @Search parameter. I have a .NET application where I will pass the string to be searched in the @Search parameter which can be either English or Arabic.

推荐答案

因为你需要在字符串字面量前加上 N 来标识它是一个 Unicode 字符串,否则它会被视为尽管它只包含单字节字符.

Because you need to prefix a string literal with N to identify it as a Unicode string, otherwise it is treated at though it only contains single-byte characters.

您能否详细说明我想让我的查询动态化"?

Can you elaborate on "I want to make my query dynamic"?

Declare     @Search    NVARCHAR(MAX) = 'اختبار كتاب اللغة العربية'

当您执行此行时,它将字符串文字视为单字节文字并将其分配给变量@Search.该变量能够存储一个 unicode 字符串(但您没有为其分配一个).当您稍后引用它时,文本已经被修改,并且您已经丢失了一些编码并且无法恢复.您必须在将文字分配给变量时在文字前面加上 N 前缀.

When you execute this line it is treating the string literal as a single-byte literal and assigning it to the variable @Search. The variable is capable of storing a unicode string (but you didn't assign one to it). By the time you reference it later, the text has already been modified and you have already lost some of the encoding and it can't be recovered. You have to prefix the literal with N at the point you assign it to the variable.

是否有理由不能在脚本中添加该前缀?

Is there are reason why you can't put that prefix in your script?

这篇关于选择查询给出输出为 ???????????不同语言的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆