sqlserver 过滤重复记录

/*
Author: liulf
Purpose: 去除重复数据
*/
alter Proc P_FilterRepeatData
 @sql varchar(8000)
as
begin
set @sql = '
if exists (select * from tempdb.dbo.sysobjects where name like ''''#wf_liulf_tmp%'''' and type=''''U'''')  
 drop table #wf_liulf_tmp
 select * into #wf_liulf_tmp from ( '+@sql+')f';
 exec (@sql)
 select * from #wf_liulf_tmp t1
 where  exists
 (
  select doc_id from (select doc_id=max(doc_id),doc_title from #wf_liulf_tmp group by doc_title)t2
  where t1.doc_id = t2.doc_id
 )
end

你可能感兴趣的:(sqlserver)