CREATE FUNCTION [dbo].[Fn_SplitStr]
(
@param VARCHAR(MAX),
@delimiter CHAR(1) = ','
)
RETURNS @t TABLE (val varchar(100), seq INT)
AS
BEGIN
SET @param += @delimiter;
WITH a AS
(
SELECT CAST(1 AS BIGINT) f, CHARINDEX(@delimiter, @param) t, 1 seq
UNION ALL
SELECT t + 1, CHARINDEX(@delimiter, @param, t + 1), seq + 1
FROM a
WHERE CHARINDEX(@delimiter, @param, t + 1) > 0
)
INSERT @t
SELECT SUBSTRING(@param, f, t - f) , seq FROM a
OPTION (MAXRECURSION 0)
RETURN
END
GO
运行结果如下:
文章来源地址https://www.toymoban.com/news/detail-817497.html
文章来源:https://www.toymoban.com/news/detail-817497.html
到了这里,关于【SQL SERVER】Fn_SplitStr 逗号相隔的字符串返回多行的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!