yu-shang

sql server默认不区分大小写查询,但是有的时候部分查询语句却需要区分大小写查询,这个时候就需要进行一些特殊处理。区分大小写主要分两种方法。

转二进制判断

select * from table where cast(name as varbinary)=cast(\'LiYuanBa\' as varbinary)               --短字符串
select * from table where cast(name as varbinary)=cast(\'LiYuanBaABCEDEF……\' as varbinary(500)) --长字符串

注意

varbinary默认长度为30,如果长度不够不保留超出的部分,最终导致判断错误!

通过collate Chinese_PRC_CS_AS

select * from table where name collate Chinese_PRC_CS_AS=\'LiYuanBa\'        --精确
select * from table where name collate Chinese_PRC_CS_AS like \'LiYuanBa%\'  --模糊

优点
不需要考虑字符串长度问题,建议使用。

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-12-23
  • 2021-10-02
  • 2021-09-21
相关资源
相似解决方案