declare @t1 table(id int identity(1,1),name varchar(20))
declare @t2 table(name varchar(20))
insert @t1(name)
select 'VABD' union all
select 'ABCD' union all
select 'ABCDEF' union all
select 'BCDEF' union all
select 'BCDEGESR' union all
select 'BCxy' union all
select 'ABGESR'
insert @t2
select 'ABC' union all
select 'BCD' select distinct a.* from @t1 a inner join @t2 b on a.name like '%' + b.name + '%'
--或
select distinct a.* from @t1 a,@t2 b where a.name like '%' + b.name + '%'/*结果
id name
2 ABCD
3 ABCDEF
4 BCDEF
5 BCDEGESR
*/
declare @t2 table(name varchar(20))
insert @t1(name)
select 'VABD' union all
select 'ABCD' union all
select 'ABCDEF' union all
select 'BCDEF' union all
select 'BCDEGESR' union all
select 'BCxy' union all
select 'ABGESR'
insert @t2
select 'ABC' union all
select 'BCD' select distinct a.* from @t1 a inner join @t2 b on a.name like '%' + b.name + '%'
--或
select distinct a.* from @t1 a,@t2 b where a.name like '%' + b.name + '%'/*结果
id name
2 ABCD
3 ABCDEF
4 BCDEF
5 BCDEGESR
*/
where 表1.列1 like '%'+表2.列1+'%'orselect 表1.列1,表2.列1 from 表1,表2
where charindex(表2.列1,表1.列1)>0