34,590
社区成员
发帖
与我相关
我的任务
分享
SELECT * FROM T2 WHERE NOT EXISTS(SELECT * FROM T1 WHERE CHARIDENX(T1字段,T2字段)>0)
select * from T2 where not exists(select 1 from T1 where charindex(T1.f,T2.f)>0)
select * from T1 where not exists(select 1 from T1 where charindex(T1.f,T2.f)>0)
--> 测试数据: #T1
if object_id('tempdb.dbo.#T1') is not null drop table #T1
create table #T1 (cl1 varchar(3))
insert into #T1
select 'CAN' union all
select 'CSX' union all
select 'PEK' union all
select 'SHA'
--> 测试数据: #T2
if object_id('tempdb.dbo.#T2') is not null drop table #T2
create table #T2 (cl2 varchar(11))
insert into #T2
select 'CTU-CAN-SGN' union all
select 'CAN-PEK' union all
select 'CTU-NRT' union all
select 'SHA-URC' union all
select 'SHA-CSX-LAX'
select * from #T2 where not exists(select 1 from #T1 where #T2.cl2 like '%'+cl1+'%')
/*
CTU-NRT
*/
SELECT * FROM T2 WHERE NOT EXISTS(SELECT * FROM T1 WHERE CHARINDEX(LTRIM(T1字段),LTRIM(T2字段))>0)
declare @t1 table(f varchar(100))
insert into @t1 select 'CAN'
insert into @t1 select 'CSX'
insert into @t1 select 'PEK'
insert into @t1 select 'SHA'
declare @t2 table(f varchar(100))
insert into @t2 select 'CTU-CAN-SGN'
insert into @t2 select 'CAN-PEK'
insert into @t2 select 'CTU-NRT'
insert into @t2 select 'SHA-URC'
insert into @t2 select 'SHA-CSX-LAX'
select * from @t2 a where not exists(select 1 from @t1 where charindex(f,a.f)>0)
--CTU-NRT
SELECT * FROM T2 WHERE NOT EXISTS(SELECT * FROM T1 WHERE CHARINEX(T1字段,T2字段)>0)
SELECT * FROM T2 WHERE NOT EXISTS(SELECT * FROM T1 WHERE CHARIDENX(T1字段,T2字段)>0)