--数据装载Create Table #T(Column1 varchar(20))insert #T select '040011'union all select '010021'union all select '024综合'union all select '021不知道'union all select '031不'union all select '不3'union all select '知道'
--1:求包含数字,且长度为6的集合(包含了中文)
select * from #T where Column1 like '%[0-9]%' and len(Column1)=6
--结果Column1 -------------------- 040011010021021不知道
(所影响的行数为 3 行)
--2:求包含中文,且长度为6的集合(包含了数字)
select * from #T where Column1 like '%[^0-9]%' and len(Column1)=6
--结果Column1 -------------------- 021不知道
(所影响的行数为 1 行)
--3:求包含数字,且长度为6的集合(不包含中文)
select * from #T where Column1 not like '%[^0-9]%' and len(Column1)=6--结果Column1 -------------------- 040011010021
(所影响的行数为 2 行)
--4 求所有记录只用中文的记录
select * from #T where Column1 not like '%[0-9]%'
--结果
Column1 -------------------- 知道
(所影响的行数为 1 行)
--5.求所有记录只有数字的记录
select * from #T where Column1 not like '%[^0-9]%' --结果
Column1 -------------------- 040011010021
(所影响的行数为 2 行)或者
select * from #T where isnumeric(Column1)=1
--结果
Column1 -------------------- 040011010021
--6.查询数据中那条记录包含有中文
select case when Column1 like N'%[啊-座]%' then '包含中文' else '不包含中文' endfrom #T
--结果
---------- 不包含中文不包含中文包含中文包含中文包含中文包含中文包含中文
(所影响的行数为 7 行)
--7:只查询数字字段值
select * from #Twhere patindex('%[^-^0-9]%',Column1 )=0
--结果
Column1 -------------------- 040011010021
(所影响的行数为 2 行)
--8:只查询中文字段值select * from #T where patindex('%[^-^啊-座]%',Column1)=0
--结果
Column1 -------------------- 知道