select 机构名称,count(机构名称)[机构名称重复个数],count(公司地址)[地址重复个数] from dbo.Excel402 group by 机构名称 having count(机构名称)>1 and count(机构名称)<>count(公司地址) select 机构名称,count(机构名称)[机构名称重复个数],count(公司地址)[地址重复个数] into #tbgroub from dbo.Excel402 group by 机构名称 select 机构名称 into #tb2 from #tbgroub where 机构名称重复个数>1 and 机构名称重复个数=地址重复个数 select * from #tb2 select * from dbo.Excel402 where 机构名称 in (select 机构名称 from #tbgroub where 机构名称重复个数>1 and 机构名称重复个数=地址重复个数 ) select (select top 1 code from Excel402 a where a.机构名称=#tb2.机构名称)[code2] into #tbcode from #tb2 select * from #tbcode select * into TestTb from dbo.Excel402 where Code in (select * from #tbcode) select * from TestTb --drop table TestTb update TestTb set TestTb.办公电话=TestTb.办公电话+','+[电话1], TestTb.邮箱地址=TestTb.邮箱地址+','+[邮箱1], TestTb.传真=TestTb.传真+','+[传真2] from TestTb inner join (select 机构名称,办公电话 [电话1],传真[传真2],邮箱地址 [邮箱1] from Excel402 where 机构名称 in (select * from #tb2) and Code not in (select * from #tbcode )) b on TestTb.机构名称=b.机构名称