--要这个效果吗? --测试数据 if object_id('table1') is not null drop table table1 go create table table1 (id varchar(10), content varchar(10)) insert table1 select '0002', 'jjj' union all select '0005', 'jj' union all select '0006', 'fff'if object_id('table2') is not null drop table table2 go create table table2(id varchar(10), content varchar(10)) insert table2 select '0002-1', 'fefe' union all select '0002-2', 'fg' union all select '0005-1', 'ffs' union all select '0005-3', 'dfs' union all select '0006-1', 'fdsf'--查询示例 select * from table1 join table2 on charindex(table1.id, table2.id)<>0
--测试数据
if object_id('table1') is not null drop table table1
go
create table table1 (id varchar(10), content varchar(10))
insert table1 select '0002', 'jjj'
union all select '0005', 'jj'
union all select '0006', 'fff'if object_id('table2') is not null drop table table2
go
create table table2(id varchar(10), content varchar(10))
insert table2 select '0002-1', 'fefe'
union all select '0002-2', 'fg'
union all select '0005-1', 'ffs'
union all select '0005-3', 'dfs'
union all select '0006-1', 'fdsf'--查询示例
select *
from table1 join table2
on charindex(table1.id, table2.id)<>0