读书人

求一SQL关于include,该怎么处理

发布时间: 2012-02-27 10:00:22 作者: rapoo

求一SQL,关于include

有一表结构:
编号 指定人 时间
id assign time
记录 001 test ..
002 test,test1 ...
003 test1,test2 ...


现在想从中选出指定人(assign)包含test值的记录,即想选出001和002记录来,这个sql 的条件怎么写,请大虾赐教,谢谢!

select * from dtl where ...... ?

[解决办法]
select * from dtl
where assign = 'test' or assign like 'test,%' or assign like '%,test' or assign like '%,test,%'

[解决办法]

SQL code
select * from dtl where charindex(','+'test'+',' , ','+assign+',')>0
[解决办法]
同意楼上的
[解决办法]
SQL code
有一表结构:        编号   指定人            时间        id    assign          time 记录   001   test            ..       002   test,test1      ...       003   test1,test2     ... 方法一:select * from tb where ','+指定人+',' like '%,test,%'方法二:select * from tb where charindex(',test,' , ','+指定人+',') > 0
[解决办法]
SQL code
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                 NULL002        test,test1           NULL(所影响的行数为 2 行)*/--方法二:select * from tb where charindex(',test,' , ','+指定人+',') > 0 /*编号         指定人                  时间                                                     ---------- -------------------- ------------------------------------------------------ 001        test                 NULL002        test,test1           NULL(所影响的行数为 2 行)*/drop table tb
[解决办法]
select * from tb where
contains(assign,'test') or contains(assign,',test') or contains(assign,'test,')

读书人网 >SQL Server

热点推荐