日期:2014-05-18 浏览次数:20661 次
go
if object_id('test') is not null
drop table test
go
create table test(
HM varchar(20)
)
go
insert test
select '01 02 04 05' union all
select '01 02 05 06' union all
select '03 08 09 22'
--如果是查询03字符存在的字段
select * from test
where CHARINDEX(' '+'03'+' ',' '+HM+' ')=0
/*
HM
01 02 04 05
01 02 05 06
*/
--如果是查询01,02,05存在的字段
select * from test
where CHARINDEX(' '+'01'+' ',' '+HM+' ')>0
and CHARINDEX(' '+'02'+' ',' '+HM+' ')>0
and CHARINDEX(' '+'05'+' ',' '+HM+' ')>0
/*
HM
01 02 04 05
01 02 05 06
*/
------解决方案--------------------
select * from tb where charindex('01',HM)>0
and charindex('02',HM)>0
and charindex('05',HM)>0