简体   繁体   中英

Case sensitive matching in IN clause in SQL

I have 2 rows in my table like this

  • name: Charlie id: 26
  • name: Frank id: 28

I want a case sensitive comparison.

I wrote a query like this

select *  
from table1 
where name in ('charlie', 'Frank') COLLATE Latin1_General_CS_AS; 

but it is not working. What should be the query?

You need to change your column to case sensitive. Something like:

ALTER TABLE table1
ALTER COLUMN name VARCHAR(100) 
COLLATE SQL_Latin1_General_CP1_CS_AS

See https://stackoverflow.com/a/485394/224370 which is a slightly different question, but same answer applies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM