declare @counts int
declare @id int
select ThreadID, count(*) as Counts into tempTable from [ArchivedMSDNThreads]
group by ThreadID
having count(*)>1 order by count(*) desc
while exists (select * from tempTable)
begin
select top(1) @counts = Counts,@id = ThreadID from tempTable
delete top(@counts - 1) from [ArchivedMSDNThreads] where ThreadID = @id
delete top(1) from tempTable
end
drop table tempTable