34,575
社区成员
发帖
与我相关
我的任务
分享
create table tb( 编号 varchar(10),指定人 varchar(20),时间 datetime)
insert into tb values('001','test',null)
insert into tb values('002','test,test1',null)
insert into tb values('003','test1,test2',null)
go
--方法一:
select * from tb where ','+指定人+',' like '%,test,%'
/*
编号 指定人 时间
---------- -------------------- ------------------------------------------------------
001 test NULL
002 test,test1 NULL
(所影响的行数为 2 行)
*/
--方法二:
select * from tb where charindex(',test,' , ','+指定人+',') > 0
/*
编号 指定人 时间
---------- -------------------- ------------------------------------------------------
001 test NULL
002 test,test1 NULL
(所影响的行数为 2 行)
*/
drop table tb
有一表结构:
编号 指定人 时间
id assign time
记录 001 test ..
002 test,test1 ...
003 test1,test2 ...
方法一:
select * from tb where ','+指定人+',' like '%,test,%'
方法二:
select * from tb where charindex(',test,' , ','+指定人+',') > 0
select * from dtl where charindex(','+'test'+',' , ','+assign+',')>0