Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot insert character '≤' in SQL Server 2008

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.

like image 264
Darko Romanov Avatar asked Feb 26 '23 16:02

Darko Romanov


1 Answers

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'
like image 135
Martin Smith Avatar answered Mar 07 '23 22:03

Martin Smith