编辑器加载中... SELECT dbo.ContionsInters('2,3,1,33',333)>0
select * from [split]('1,2,3',',')
--创建函数 ,处理 字符串是否包含,指定的字符
alter FUNCTION [dbo].ContionsInters ( @ids NVARCHAR(1024) ,@Targetid INT )
RETURNS int
AS
begin
DECLARE @count INT SELECT @count= COUNT(*) FROM split(@ids,',') WHERE col=@Targetid
RETURN @count
END
CREATE function [dbo].[split](@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin while(charindex(@split,@c)<>0) begin insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end insert @t(col) values (@c)
return
end