中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 数据库开发 > 数据库综合
查询区分大小写
作者:未知 时间:2004-02-07 12:12 出处:Blog 责编:chinaitpower
              摘要:暂无

在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 行)
--*/

 

 

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有