34,587
社区成员
发帖
与我相关
我的任务
分享
if OBJECT_ID(N'tempdb.dbo.#t1') is not null drop table #t1
create table #t1(id int)
insert into #t1
select 985 union all
select 456 union all
select 789 union all
select 112 union all
select 2135 union all
select 6132
if OBJECT_ID(N'tempdb.dbo.#t2') is not null drop table #t2
create table #t2(id int)
insert into #t2
select 12 union all
select 78
SELECT * FROM #t1 AS a WHERE NOT EXISTS (
SELECT 1 FROM #t2 AS b WHERE CAST(a.id AS VARCHAR(50)) LIKE '%'+CAST(b.id AS VARCHAR(50)) +'%'
)
/*
id
985
456
2135
6132
*/
if OBJECT_ID(N'tempdb.dbo.#t1') is not null
drop table #t1
go
create table #t1
(id int)
insert into #t1
select 985 union all
select 456 union all
select 789 union all
select 112 union all
select 2135 union all
select 6132
if OBJECT_ID(N'tempdb.dbo.#t2') is not null
drop table #t2
go
create table #t2
(id int)
insert into #t2
select 12 union all
select 78
select *
from #t1 A
where not exists (select 1 from #t2 B where CHARINDEX(LTRIM(B.id),LTRIM(A.id))>0)