简体   繁体   中英

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) .

Now that I update in the database and see that instead of Ha : µ ≠µ0 , I get

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. Like this:

 update Qtable set Q1=' If the alternative 
 hypothesis is as  Ha :'+ N'µ ≠µ0'   ;
    where QID='856'

QUERY 1: (OLD Query's String)

SELECT 'If the alternative 
 hypothesis is as  Ha:µ ≠µ0';

OUTPUT:

If the alternative hypothesis is as Ha:µ ?µ0

QUERY 2: (NEW Query's String)

 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:

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 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.

Use this statement:

update Qtable 
set Q1 = N'If the alternative hypothesis is as  Ha : µ ≠µ0' 
where QID = '856'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM