ALTER FUNCTION [dbo].[UFun_SqlSplit] (@Str varchar(120),@Sp varchar(120))
RETURNs @table TABLE(
ID int IDENTITY PRIMARY KEY,
value nvarchar(max)
)
BEGIN
/*
Test:
select * from SqlSplit('123,234',',')
*/
IF LEN(@Str)<1
return;
DECLARE @pos int
DECLARE @temppos int
SET @pos =0;
WHILE(CHARINDEX(@Sp,@Str,0)>0)
BEGIN
SET @temppos =CHARINDEX(@Sp,@Str,0)
INSERT INTO @table VALUES(substring(@Str,1,@temppos-1))
SET @Str=substring(@Str,@temppos+1,len(@Str))
END
INSERT INTO @table VALUES(@Str)
RETURN
END