[英]Storing some special characters in SQL Server tables
I have the following query:我有以下查询:
update Qtable
set Q1 = ' If the alternative
hypothesis is as Ha : µ ≠µ0 ;
where QID = '856'
Q1
is of datatype nvarchar(max)
. Q1
的数据类型为nvarchar(max)
。
Now that I update in the database and see that instead of Ha : µ ≠µ0
, I get现在我在数据库中更新并看到不是
Ha : µ ≠µ0
,我得到
Ha : µ ?µ0
Not sure why the update statement replaces ≠ with ?不知道为什么更新语句用 ≠ 替换? I understand its a special character but what settings should be applied to preserve the value?
我知道它是一个特殊字符,但是应该应用哪些设置来保留该值?
You need to be sure that you prefix Unicode string literals with an N prefix.您需要确保为 Unicode 字符串文字加上 N 前缀。 Like this:
像这样:
update Qtable set Q1=' If the alternative
hypothesis is as Ha :'+ N'µ ≠µ0' ;
where QID='856'
QUERY 1: (OLD Query's String) QUERY 1:(旧查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:µ ≠µ0';
OUTPUT:输出:
If the alternative hypothesis is as Ha:µ ?µ0
QUERY 2: (NEW Query's String) QUERY 2:(新查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:' + N'µ ≠µ0';
OUTPUT:输出:
If the alternative hypothesis is as Ha:µ ≠µ0
FOR DEMO Check the below link: FOR DEMO 检查以下链接:
http://sqlfiddle.com/#!18/adfb7/1
http://sqlfiddle.com/#!18/adfb7/1
If you are not using NVARCHAR then you will get your not equal character
replaced by some other character.如果您不使用 NVARCHAR,那么您的
not equal character
将被其他字符替换。
Nvarchar stores UNICODE data.
Nvarchar 存储 UNICODE 数据。 If you have requirements to store UNICODE or multilingual data, nvarchar is the choice.
如果您需要存储 UNICODE 或多语言数据,nvarchar 是您的选择。 Varchar stores ASCII data and should be your data type of choice for normal use.
Varchar 存储 ASCII 数据,应该是您正常使用的数据类型选择。
Use this statement:使用此语句:
update Qtable
set Q1 = N'If the alternative hypothesis is as Ha : µ ≠µ0'
where QID = '856'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.