ALTER FUNCTION [dbo].[SplitTextIntForTest1]
(
-- Add the parameters for the function here
@text VARCHAR(5000),
@delimiter CHAR(1)
)
RETURNS @Table TABLE ([Value] INT)
AS
BEGIN
;WITH csvtbl([INDEX],[NEXT])
AS
(
SELECT [INDEX]=1, [NEXT]=CHARINDEX(@delimiter,@text + @delimiter)
UNION ALL
SELECT [INDEX]=[NEXT]+1, [NEXT] = CHARINDEX(@delimiter,@text + @delimiter,[NEXT] + 1)
FROM csvtbl
WHERE CHARINDEX(@delimiter,@text + @delimiter,[NEXT]+1) <> 0
)
INSERT INTO @Table([Value])
SELECT SUBSTRING(@text,[INDEX],[NEXT]-[INDEX]) AS [Value]
FROM csvtbl OPTION (MAXRECURSION 32767)
RETURN
END
select * from dbo.SplitTextIntForTest('2,3,5,3,5,6,7')
SqlServer Function(SplitText)
最新推荐文章于 2021-11-30 16:58:14 发布