ALTER FUNCTION atp_MakeCodeList
(
-- Add the parameters for the function here
@liststr nvarchar(4000)
)
RETURNS
@result TABLE
(
code nvarchar(255)
)
AS
BEGIN
-- Fill the table variable with the rows for your result set
declare @cindex int;
declare @newcode nvarchar(255);
declare @newliststr nvarchar(4000);
set @newliststr = @liststr;
set @cindex = charindex( ',', @newliststr );
while( @cindex > 0 )
begin
set @newcode = substring( @newliststr, 1, @cindex - 1 );
insert into @result values( @newcode );
set @newliststr = right( @newliststr, len(@newliststr) - @cindex );
set @cindex = charindex( ',', @newliststr );
end
insert into @result values( @newliststr );
RETURN
END
SqlServer 函数 分割字符串并返回
最新推荐文章于 2024-08-17 22:30:13 发布
该SQL函数atp_MakeCodeList接收一个包含逗号分隔值的字符串参数@liststr,并将其拆分为单独的行存储在结果表中。通过循环处理,每次截取从字符串开始到逗号出现之前的部分,然后插入到结果表。最后,将剩余的字符串(不包含逗号)也插入到结果表中。
3424

被折叠的 条评论
为什么被折叠?



