SQL SERVER 查询数据默认是不区分大小写的.也即以下两个语句查出的结果是一样的:
1.select * from tablea where field1 ='c'
2.select * from tablea where field1 ='C
那么,要如何使SQL 查询出来的数据是区分大小写的呢,很简单,只要加上一个函数即可:collate chinese_prc_cs_as_ws
select * from tablea where field1 collate chinese_prc_cs_as_ws ='c'
这里查出来的就会只有小写'c'的了.
select * from tablea where field1 collate chinese_prc_cs_as_ws like 'c%'
则只会出查以'c'开头的数据.
也许有人会说:使用varbinary也可做到.其实不然,它对于精确查找没有问题,可是对于模糊查询却无能为力了.如下两个句子查出来的数据是一样的:
select * from tablea where convert (varbinary,field1 ) like convert (varbinary,'aB%')
select * from tablea where convert (varbinary,field1 ) like convert (varbinary,'ab%')