两张表做匹配
table1 table2
col1 col2 col1 col2
1 aa 1 12-df.fas-aa.hh
2 bb 2 fdsa-cc.mk-123
3 cc 3 32-bb.iuyi-87987asdf
结果为
table3
col1 col2 col3
1 aa 12-df.fas-aa.hh
2 bb 32-bb.iuyi-87987asdf
3 cc fdsa-cc.mk-123意思就是在table2中的col2中找到包含table1中col2中的记录插入table1的第三列
谢谢各位大哥,在线等!
table1 table2
col1 col2 col1 col2
1 aa 1 12-df.fas-aa.hh
2 bb 2 fdsa-cc.mk-123
3 cc 3 32-bb.iuyi-87987asdf
结果为
table3
col1 col2 col3
1 aa 12-df.fas-aa.hh
2 bb 32-bb.iuyi-87987asdf
3 cc fdsa-cc.mk-123意思就是在table2中的col2中找到包含table1中col2中的记录插入table1的第三列
谢谢各位大哥,在线等!
From table1 A Inner Join table2 B
On A.col1 = B.col1
From table1 A, table2 B Where A.col1 = B.col1
From table1 A Inner Join table2 B
On A.col1 = B.col1或者Select A.*, B.col2 As col3 Into table3
From table1 A, table2 B Where A.col1 = B.col1
FROM table1 INNER JOIN table2 ON table1.col1=table2.col1
...........
你们看帖哇~晕死
Select A.*, B.col2 As col3
From table1 A Inner Join table2 B
On B.col2 Like '%' + A.col2 + '%'Select A.*, B.col2 As col3
From table1 A, table2 B Where B.col2 Like '%' + A.col2 + '%'
insert into #table1
select 1 , 'aa' union all
select 2 , 'bb' union all
select 3 , 'cc'
create table #table2(col1 int, col2 varchar(20) )
insert into #table2
select 1 , '12-df.fas-aa.hh' union all
select 2 , 'fdsa-cc.mk-123' union all
select 3 , '32-bb.iuyi-87987asdf'select a.*,b.col2
from #table1 a , #table2 b
where CHARINDEX (a.col2,b.col2)>0
col1 col2 col2
----------- -------------------- --------------------
1 aa 12-df.fas-aa.hh
3 cc fdsa-cc.mk-123
2 bb 32-bb.iuyi-87987asdf(所影响的行数为 3 行)
create table tbl1(col1 int, col2 varchar(20) )
insert into tbl1
select 1 , 'aa' union all
select 2 , 'bb' union all
select 3 , 'cc'
create table tbl2(col1 int, col2 varchar(20) )
insert into tbl2
select 1 , '12-df.fas-aa.hh' union all
select 2 , 'fdsa-cc.mk-123' union all
select 3 , '32-bb.iuyi-87987asdf'create table tbl3(col1 int, col2 varchar(20),col3 varchar(30) )insert into tbl3 select a.col1,a.col2,b.col2 from tbl1 a,tbl2 b
where charindex(a.col2,b.col2)>0select * from tbl3
col1 col2 col3
----------- -------------------- ------------------------------
1 aa 12-df.fas-aa.hh
3 cc fdsa-cc.mk-123
2 bb 32-bb.iuyi-87987asdf(3 行受影响)