时间:2021-07-01 10:21:17 帮助过:101人阅读
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
sql server判断是否重复值
标签:sqlserver 查找重复值 sql 临时表