数据表1
如table1
tcid 公司名称 性别 备注
1 a n 123
3 b f 256
数据表2
talbe2
listid 联系人姓名 单位 状态 性别
5 v f 145 n
1 d h 178 f
要合并成数据表3 这个样子要咋弄呢?
tcid 公司名称 性别 备注 listid 联系人姓名 单位 状态
1 a n 123 5 v f 145
3 b f 256 1 d h 178
------解决方案--------------------
试试这个:
if OBJECT_ID('#tempdb..#table1') is not null
drop table #table1
if OBJECT_ID('#tempdb..#table2') is not null
drop table #table2
select IDENTITY(int,1,1) id,* into #table1
from table1
select IDENTITY(int,1,1) id,* into #table2
from table2
select tcid,公司名称,a.性别,备注,listid,联系人姓名,单位,状态
from #table1 a
inner join #table2 b
on a.id = b.id