--0.备份当前db的dindansp3表到dindansp3_back
select [id],[spid],[name],[count]
into [db].[dbo].[dindansp3_back] from [db].[dbo].[dindansp3]
go

--1.将2014和db的dindnasp3表的全部记录插入到#tempall中;
select [id],[spid],[name],[count]
into #tempall  from [db].[dbo].[dindansp3]
go

insert into #tempall
select [id],[spid],[name],[count] from [2014].[dbo].[dindansp3]
go

--2.过滤掉#tempall中完全重复的记录到#tempdis中;
select distinct * into #tempdis from #tempall
go

drop table #tempall
go

--3.获取指定字段的不重复记录,过滤掉不完全重复的记录;
select identity(int,1,1) as autoid, * into #temp1 from #tempdis
select min(autoid) as autoid into #temp2 from #temp1 group by [id],[spid],[name],[count]
select [id],[spid],[name],[count]
into [db].[dbo].[dindansp3#] from #temp1 where autoid in(select autoid from #temp2) order by id
go

--4.将过滤好的记录重新插入原表;
truncate table [db].[dbo].[dindansp3]
go

insert into [db].[dbo].[dindansp3]([id],[spid],[name],[count]) 
select [id],[spid],[name],[count] from [db].[dbo].[dindansp3#] 
go

drop table #tempdis 
drop table #temp1 
drop table #temp2 
drop table [db].[dbo].[dindansp3#] 
go
--5.结束