Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question mark is not visible

Tags:

sql

select case when 'A​B' = 'A?B' then 1 else 0 end

Result:1

Why is the question mark in the first string not visible?

Does anyone know a fix for this?

like image 816
Grace Avatar asked Jan 06 '16 09:01

Grace


1 Answers

That first 'AB' is really (A) (zero width space) (B).

For SqlServer a quoted string without an N prefix is treated as a single-byte-per-character string. Apparently the "non ascii" zero width space is translated into a question mark before comparing.

Adding the "N-prefix" gives the expected result (0):

select case when N'A​B' = N'AB' then 1 else 0 end
like image 167
Hans Kesting Avatar answered Oct 14 '22 07:10

Hans Kesting