查询区分大小写
来源:互联网 发布:行政管理网络教育 编辑:程序博客网 时间:2024/05/17 07:02
在sql2000和7.0的查询语句中,区分大写的查询方法
--sql2000,就用下面的方法.
--就是在字段名后加 collate Chinese_PRC_CS_AS_WS
--区分大小写、全半角字符的方法
--测试数据
create table 表(fd varchar(10))
insert into 表
select aa='aa'
union all select 'Aa'
union all select 'AA' --全角A
union all select 'A,A' --全角A,半角,
union all select 'A,A' --全角A,全角,
go
--查询
--1.查大写字母
select * from 表
where fd collate Chinese_PRC_CS_AS_WS like '%A%'
--就是在字段名后加 collate Chinese_PRC_CS_AS_WS
--2.查全角
select * from 表
where fd collate Chinese_PRC_CS_AS_WS like '%A%'
--3.查半角
select * from 表
where fd collate Chinese_PRC_CS_AS_WS like '%,%'
go
--删除测试数据
drop table 表
/*--测试结果
1.查询大写字母的结果
fd
----------
Aa
2.查询全角字符的结果
fd
----------
AA
A,A
A,A
3.查询半角字符的结果
fd
----------
A,A
(所影响的行数为 1 行)
--*/
================================================================
--sql7.0,就用下面的方法.
--如果是全部比较
--下面是测试
select * from(
select fd='a'
union all select 'A'
) a
where cast(fd as varbinary(8000))=cast('A' as varbinary(8000))
/*--测试结果
fd
----
A
(所影响的行数为 1 行)
--*/
--如果是部分匹配,就用charindex:
--下面是测试
select * from(
select fd='a'
union all select 'A'
union all select 'aAaa'
union all select 'aaaa'
union all select 'cccA'
) a
where charindex(cast('A' as varbinary(8000)),cast(fd as varbinary(8000)))>0
/*--测试结果
fd
----
A
aAaa
cccA
(所影响的行数为 3 行)
--*/
- 查询区分大小写
- 查询区分大小写
- SQL查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 查询区分大小写
- 数据库管理员DBA
- 完成端口及网络编程之QA(常见问题,持续添加)
- 认识“Silverlight”
- [AD]商业价值被发现,国内博客们的两件喜事
- Silverlight技术应用篇“photo viewer”动画效果欣赏
- 查询区分大小写
- 为OpenSource担忧---从在weblogic下使用webwork2说起
- 完成端口之性能优化(2)
- 修改ComboBox控件模板实例
- WPF中如何解决3d模型与贴图不能完全匹配的问题
- 完成端口中的单句柄数据结构与单IO数据结构的理解与设计
- 4. Lambda Expressions (Lambda表达式)与Expressions Tree(表达式树)
- 得到对象脚本
- Annotations:hype or not?