34,838
社区成员




--1
create table t1
(
no varchar(10)
)
insert into t1
select 'LSV123' union all
select 'LBV124' union all
select 'LBV126' union all
select 'LCV225' union all
select 'DVB630'
go
create table t2
(
no varchar(10)
)
insert into T2
select '123' union all
select '126' union all
select '225'
go
--2
;with newtb as(
select no, right(no,3) as co from t1
)
select newtb.no from newtb left join t2 on t2.no=newtb.co where t2.no is not null
--no
------------
--LSV123
--LBV126
--LCV225
--
--(3 行受影响)
--3
drop table t1,t2
create table t1(id int,nob varchar(10))
insert into t1
select 1,'LSV123' union all
select 2,'LBV124' union all
select 3,'LBV126' union all
select 4,'LCV225' union all
select 5,'DVB630'
go
create table t2(noe varchar(10))
insert into t2
select '123' union all
select '126' union all
select '225'
go
select nob from(
select * from (select nob from t1)b cross apply (select ltrim(noe)a from t2) ar
)temp
where charindex(a,nob)>0
drop table t1,t2
nob
----------
LSV123
LBV126
LCV225
(3 行受影响)
create table t1
(
no varchar(10)
)
create table t2
(
no varchar(10)
)
insert into t1
select 'LSV123' union all
select 'LBV124' union all
select 'LBV126' union all
select 'LCV225' union all
select 'DVB630'
insert into T2
select '123' union all
select '126' union all
select '225'
select t1.* from t1 join T2 on CHARINDEX(T2.no,T1.no)>0
/*------------------
no
LSV123
LBV126
LCV225
*/