Create FUNCTION [dbo].[fn_split]
(
-- Add the parameters for the function here
@vinput nvarchar(max),@vsplit nvarchar(1)
)
RETURNS
@ReTable TABLE
(
-- Add the column definitions for the TABLE variable here
Column_1 nvarchar(max)
)
AS
BEGIN
-- Fill the table variable with the rows for your result set
declare @inString nvarchar(max)
declare @CHPoint int
declare @vinndex int
-- set @vinndex=CHARINDEX(@vsplit,@vinput)
set @CHPoint=0
while (@CHPoint<1)
begin
set @vinndex=CHARINDEX(@vsplit,@vinput)
if @vinndex>0
begin
set @inString=substring(@vinput,1,@vinndex-1)
set @vinput=substring(@vinput,@vinndex+1,len(@vinput)-@vinndex)
end
else
begin
set @CHPoint=1
set @inString=@vinput
end
if @inString<>@vsplit and @inString<>''
insert into @ReTable(Column_1) values (@inString)
end
RETURN
END
______________________________________________________________________________________________________
SQL Server 2016 (13.x) 和更新版本
有提供
STRING_SPLIT
留言列表