国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

查詢區分大小寫

2024-07-21 02:08:24
字體:
來源:轉載
供稿:網友

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

 

 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奎屯市| 西乌| 秭归县| 梁山县| 长阳| 怀柔区| 上高县| 霞浦县| 武冈市| 安阳县| 金溪县| 河曲县| 大丰市| 苏尼特左旗| 天峨县| 台前县| 滦平县| 越西县| 南康市| 横峰县| 卢龙县| 资源县| 交口县| 隆安县| 平阳县| 玉溪市| 吕梁市| 杭州市| 宣汉县| 河西区| 徐水县| 西青区| 卢龙县| 克拉玛依市| 天台县| 北京市| 镇远县| 平江县| 双牌县| 昌邑市| 肃南|