Chhorn Soro
Chhorn Soro

Reputation: 3141

SQL Server Query Unicode String

I have a table UserType:

 id (int),
 type nvarchar(50)

I have inserted some rows into that table

 INSERT INTO [UserType] VALUES (N'កក្កដា');
 INSERT INTO [UserType] VALUES (N'វិច្ឆិកា');

And it's successfully inserted.

Then when I tried to query it back

select * 
from [UserType] 
where type=N'កក្កដា';

It returns all rows.

What's wrong? Please help!

Upvotes: 3

Views: 3050

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93694

Looks like you database is Accent Insensitive.

You need to explicitly mention the proper collation name in where clause to filter the proper data.

Use Latin1_General_100_CI_AS collation which is accent sensitive. Try this.

SELECT *
FROM   [UserType]
WHERE  type = CONVERT(NVARCHAR(50), N'វិច្ឆិកា') COLLATE Latin1_General_100_CI_AS; 

Upvotes: 6

Related Questions