Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering unicode column in Sql server 2005 - to much data match

I have a simple table:

CREATE TABLE [dbo].[Users]([Surname] [nvarchar](50) COLLATE Latin1_General_CI_AI NULL) ON [PRIMARY]

with two rows:

Paweł
Pawel

Issuing following select statement:

SELECT *, CAST(Surname AS VARBINARY(30)) AS Expr1, CAST(N'Paweł' AS VARBINARY(30)) AS Expr1 
FROM Users WHERE Surname = N'Paweł'

gives following result:

Paweł   0x50006100770065004201  0x50006100770065004201
Pawel   0x50006100770065006C00  0x50006100770065004201

Row with value 'Pawel' is returned , even though it's not equal to 'Paweł' (binary columns show it).

Any idea what is going on, how come SQL server considers Pawel = Paweł in that case?

Thanks, Paweł

like image 397
dragonfly Avatar asked May 09 '26 03:05

dragonfly


1 Answers

Your collation is accent insensitive: Latin1_General_CI_AI

Try something like this:

select 1 where N'Pawel' = N'Paweł' collate Latin1_General_100_CI_AS

Returns nothing as expected.

like image 101
Denis Valeev Avatar answered May 10 '26 16:05

Denis Valeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!