在 SQL 服务器表中存储一些特殊字符
Storing some special characters in SQL Server tables
我有以下查询:
update Qtable
set Q1 = ' If the alternative
hypothesis is as Ha : µ ≠µ0 ;
where QID = '856'
Q1
的数据类型为 nvarchar(max)
。
现在我在数据库中更新并看到 Ha : µ ≠µ0
,我得到
Ha : µ ?µ0
不确定为什么更新语句将≠替换为?我知道它是一个特殊字符,但应该应用哪些设置来保留该值?
您需要确保为 Unicode 字符串文字添加 N 前缀。
像这样:
update Qtable set Q1=' If the alternative
hypothesis is as Ha :'+ N'µ ≠µ0' ;
where QID='856'
QUERY 1:(旧查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:µ ≠µ0';
输出:
If the alternative hypothesis is as Ha:µ ?µ0
QUERY 2:(新查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:' + N'µ ≠µ0';
输出:
If the alternative hypothesis is as Ha:µ ≠µ0
用于演示检查此 link:
http://sqlfiddle.com/#!18/adfb7/1
如果您不使用 NVARCHAR,那么您的 not equal character
将被其他字符替换。
Nvarchar stores UNICODE data. If you have requirements to store
UNICODE or multilingual data, nvarchar is the choice. Varchar stores
ASCII data and should be your data type of choice for normal use.
使用这个语句:
update Qtable
set Q1 = N'If the alternative hypothesis is as Ha : µ ≠µ0'
where QID = '856'
我有以下查询:
update Qtable
set Q1 = ' If the alternative
hypothesis is as Ha : µ ≠µ0 ;
where QID = '856'
Q1
的数据类型为 nvarchar(max)
。
现在我在数据库中更新并看到 Ha : µ ≠µ0
,我得到
Ha : µ ?µ0
不确定为什么更新语句将≠替换为?我知道它是一个特殊字符,但应该应用哪些设置来保留该值?
您需要确保为 Unicode 字符串文字添加 N 前缀。 像这样:
update Qtable set Q1=' If the alternative
hypothesis is as Ha :'+ N'µ ≠µ0' ;
where QID='856'
QUERY 1:(旧查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:µ ≠µ0';
输出:
If the alternative hypothesis is as Ha:µ ?µ0
QUERY 2:(新查询的字符串)
SELECT 'If the alternative
hypothesis is as Ha:' + N'µ ≠µ0';
输出:
If the alternative hypothesis is as Ha:µ ≠µ0
用于演示检查此 link:
http://sqlfiddle.com/#!18/adfb7/1
如果您不使用 NVARCHAR,那么您的 not equal character
将被其他字符替换。
Nvarchar stores UNICODE data. If you have requirements to store UNICODE or multilingual data, nvarchar is the choice. Varchar stores ASCII data and should be your data type of choice for normal use.
使用这个语句:
update Qtable
set Q1 = N'If the alternative hypothesis is as Ha : µ ≠µ0'
where QID = '856'