create function RepeatString(@input varchar(8000),@separator varchar(10)) returns int as begin declare @temp table(part varchar(100)) declare @i int ,@result int set @input=rtrim(ltrim(@input)) set @i=charindex(@separator,@input) while @i>=1 begin insert @temp values(left(@input,@i-1)) set @input=substring(@input,@i+1,len(@input)-@i) set @i=charindex(@separator,@input) end if exists(select part,count(*) from @temp group by part having count(*)>1) set @result=1 --存在重复 else set @result=0 --不存在重复 return @result end go
--测试
select dbo.RepeatString('1,1,2,3,1',',') --1 select dbo.RepeatString('1,2,3,4,5',',') --0
原文地址:http://blog.csdn.net/xiaoyong_net/article/details/46924541