34,837
社区成员




update t set c2 = 1 from tab1 t where exists (select 1 from tab1 a, tab2 b where a.c1=t.c1 and b.cc2=1 and charindex(b.cc1,a.c1)>0)
create table tab1(c1 varchar(20), c2 int)
insert into tab1 values('hahahaha', 0)
insert into tab1 values('lalalala', 0)
insert into tab1 values('hehehehe', 0)
create table tab2(cc1 varchar(20), cc2 int)
insert into tab2 values('haha' , 1 )
insert into tab2 values('lalaha' , 0 )
insert into tab2 values('lala' , 1 )
go
update tab1
set c2 = 1
from tab1,tab2 where tab2.cc2 = 1 and charindex(tab2.cc1,tab1.c1) > 0
select * from tab1
drop table tab1,tab2
/*
c1 c2
-------------------- -----------
hahahaha 1
lalalala 1
hehehehe 0
(所影响的行数为 3 行)
&/