34,593
社区成员
发帖
与我相关
我的任务
分享
select data,data_id=(select data_id from t1 where data_id like '%'+t2.data+'%') from t2
select a.*,b.* from t1 a inner join t2 b on a.data_id like '%'+b.data+'%'
create table t1(data_id varchar(20))
insert into t1 select
'sdfsdf45656' union all select
'rthtr565122' union all select
'12354546565' union all select
'56566444444' union all select
'xcv32344344'
create table t2(data varchar(10))
insert into t2 select '65122' union all select
'44344'
go
select a.*,b.* from t1 a inner join t2 b on a.data_id like '%'+b.data+'%'
/*
data_id data
-------------------- ----------
rthtr565122 65122
xcv32344344 44344
(2 行受影响)
*/
go
drop table t1,t2
select * from t1 a, t2 b where charindex(a.data,b.data_id)>0
select a.data,b.data_id
from t2 a,t1 b
where b.data_id like '%'+a.data+'%'