34,590
社区成员
发帖
与我相关
我的任务
分享
select * from a , b where charindex(','+a.id+',' , ','+b.id+',') > 0
select * from a join b on charindex(a.id,b.id)>0
create table A(id varchar(10))
insert into a values('0001')
insert into a values('0002')
insert into a values('0003')
insert into a values('0004')
create table B(id varchar(20))
insert into b values('0001,0002')
insert into b values('0003')
insert into b values('0004')
go
select a.* , b.* from a , b where charindex(','+a.id+',' , ','+b.id+',') > 0
/*
id id
---------- --------------------
0001 0001,0002
0002 0001,0002
0003 0003
0004 0004
(所影响的行数为 4 行)
*/
select a.* , b.* from a , b where ','+b.id+',' like '%,'+a.id+',%'
/*
id id
---------- --------------------
0001 0001,0002
0002 0001,0002
0003 0003
0004 0004
(所影响的行数为 4 行)
*/
drop table a , b
create table A(id varchar(10))
insert into a values('0001')
insert into a values('0002')
insert into a values('0003')
insert into a values('0004')
create table B(id varchar(20))
insert into b values('0001,0002')
insert into b values('0003')
insert into b values('0004')
go
select a.* , b.* from a , b where charindex(','+a.id+',' , ','+b.id+',') > 0
drop table a , b
/*
id id
---------- --------------------
0001 0001,0002
0002 0001,0002
0003 0003
0004 0004
(所影响的行数为 4 行)
*/
select a.* , b.* from a , b where charindex(','+a.id+',' , ','+b.id+',') > 0