[英]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
FOR DEMO 檢查以下鏈接:
如果您不使用 NVARCHAR,那么您的not equal character
將被其他字符替換。
Nvarchar 存儲 UNICODE 數據。 如果您需要存儲 UNICODE 或多語言數據,nvarchar 是您的選擇。 Varchar 存儲 ASCII 數據,應該是您正常使用的數據類型選擇。
使用此語句:
update Qtable
set Q1 = N'If the alternative hypothesis is as Ha : µ ≠µ0'
where QID = '856'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.