临时表那不晓得咋个写了。。USE [chext]
GO/****** Object:  StoredProcedure [dbo].[sp_unique]    Script Date: 08/26/2013 16:16:57 ******/
SET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOCREATE PROCEDURE [dbo].[sp_unique] 
@idcol nvarchar(50),
@uniquecol nvarchar(200),
@table nvarchar(50),
@datastr nvarchar(2000),
@repeat nvarchar(50) outputAS
BEGIN
SET NOCOUNT ON;
declare @sqlstr nvarchar(2000)
create table #temp(id numeric(18,0),code nvarchar(50))
select @sqlstr = N'insert into #temp values'+replace(@datastr,'),(',') insert into #temp values(')
exec(@sqlstr)
select @repeat = ''
select @repeat = a.code from #temp a,#temp b where a.code=b.code and a.id!=b.id
if @repeat = '' begin
select @sqlstr = N'select @repeat=a.code from #temp a,'+@table+N' b where a.code=b.'+@uniquecol+
N' and a.id!=b.'+@idcol
exec sp_executesql @sqlstr,N'@repeat nvarchar(50) out',@repeat out
end
END
GO