Question mark not displayed

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

Result: 1

Why is the question mark on the first line not displayed?

Does anyone know how to fix this?

+7
sql
source share
4 answers

This first 'AB' valid (A) (zero-width space) (B).

For SqlServer, a quoted string without the N prefix is ​​treated as a string with one byte for a character. Apparently, the non-ascii space with zero width is converted to a question mark before comparison.

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

 select case when N'A​B' = N'AB' then 1 else 0 end 
+4
source share

Rewrite your sql statement, do not copy or skip it, is it hidden? symbol

enter image description here

+2
source share

The question mark is encoded using these three bytes of E2 80 8B , but how? “Hell beats out of me, but it really is. Perhaps SQL internally replaces these invalid characters with one single character ? . When I open the text in the PSPad and switch to the HEX view and back, do I get the usual visible ? char.

+1
source share

You can use:

 select case when ('A​B' = 'A?B' AND LEN('A​B') = LEN('A?​B')) then 1 else 0 end 
-one
source share

All Articles