Cannot insert character '≤' in SQL Server 2008

烂漫一生 提交于 2020-01-14 10:26:07

问题


I have a SQL Server 2008 database and a nvarchar(256) field of a table. The crazy problem is that when I run this query:

update ruds_values_short_text 
set value = '≤ asjdklasd' 
where rud_id=12202 and field_code='detection_limit'

and then

select * from ruds_values_short_text  
where rud_id=12202 and field_code='detection_limit'

I get this result:

12202 detection_limit = asjdklasd 11

You can see that the character ≤ has been transformed in =

It's an encoding related problem, for sure, in fact, if I try to paste '≤' in Notepad++ it pastes '=' but I get '≤' when I convert ANSI to UTF-8.

So.. I think I should write the query in UTF8.. but how? Thanks.


回答1:


You need to use the N prefix so the literal is treated as Unicode rather than being treated as character data in the code page of your database's default collation.

update ruds_values_short_text 
set value = N'≤ asjdklasd'
where rud_id=12202 and field_code='detection_limit'



回答2:


Try update ruds_values_short_text set value = N'≤ asjdklasd' where rud_id=12202 and field_code='detection_limit'. The N indicates that you are providing national language so it respects the encoding.



来源:https://stackoverflow.com/questions/4336016/cannot-insert-character-%e2%89%a4-in-sql-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!