没有测试:try~ SELECT * FROM TB t WHERE CHARINDEX('4',SUBSTRING(字段A,2,LEN(字段A)-1)))>0
select * from tb where ','+字段A+',' like '%,4,%'
WHERE CHARINDEX(',4,',','+字段A+',')))>0
select * from tb where charindex(',4,',','+a+',')>0
select * from tb where charindex(',4,',','+字段A+',')>0
---测试数据 if object_id('tb') is not null drop table tb create table tb (id int,字段A varchar(100)) insert into tb select 1,'1,2,11,4,8,19' union all select 2,'1,2,3,4' union all select 3,'4,5,7,8' union all select 4,'4' union all select 5,'44,45,46' union all select 6,'1,2,11,41,8,19,64'--查询 select * from tb where ','+字段A+',' like '%,4,%' --结果 /* id 字段A --- --------------- 1 1,2,11,4,8,19 2 1,2,3,4 3 4,5,7,8 4 4 */
---测试数据 if object_id('tb') is not null drop table tb create table tb (id int,字段A varchar(100)) insert into tb select 1,'1,2,11,4,8,19' union all select 2,'1,2,3,4' union all select 3,'4,5,7,8' union all select 4,'4' union all select 5,'44,45,46' union all select 6,'1,2,11,41,8,19,64'--查询 select * from tb where ','+字段A+',' like '%,4,%' --结果 /* id 字段A --- --------------- 1 1,2,11,4,8,19 2 1,2,3,4 3 4,5,7,8 4 4 */ --删除测试表 drop table tb
select * from tb where charindex(',4,',','+a+',')>0
Select * from 表名 Where [字段A] like ‘%4%’ and [字段A ] not like ‘%4%4%’
SELECT * FROM TB t
WHERE CHARINDEX('4',SUBSTRING(字段A,2,LEN(字段A)-1)))>0
select * from tb where charindex(',4,',','+字段A+',')>0
if object_id('tb') is not null
drop table tb
create table tb (id int,字段A varchar(100))
insert into tb
select 1,'1,2,11,4,8,19' union all
select 2,'1,2,3,4' union all
select 3,'4,5,7,8' union all
select 4,'4' union all
select 5,'44,45,46' union all
select 6,'1,2,11,41,8,19,64'--查询
select * from tb where ','+字段A+',' like '%,4,%'
--结果
/*
id 字段A
--- ---------------
1 1,2,11,4,8,19
2 1,2,3,4
3 4,5,7,8
4 4
*/
if object_id('tb') is not null
drop table tb
create table tb (id int,字段A varchar(100))
insert into tb
select 1,'1,2,11,4,8,19' union all
select 2,'1,2,3,4' union all
select 3,'4,5,7,8' union all
select 4,'4' union all
select 5,'44,45,46' union all
select 6,'1,2,11,41,8,19,64'--查询
select * from tb where ','+字段A+',' like '%,4,%'
--结果
/*
id 字段A
--- ---------------
1 1,2,11,4,8,19
2 1,2,3,4
3 4,5,7,8
4 4
*/
--删除测试表
drop table tb
select * from tb where charindex(',4,',','+a+',')>0
Where [字段A] like ‘%4%’ and [字段A ] not like ‘%4%4%’
这位仁号,为什么我测试,只能得出
1 1,2,11,4,8,19
3 4,5,7,8你却能得出项4adm
13#的没有问题。
你先把他的代码全部copy到你的查询分析器,看看结果。
我这边测试是正确的。