begin
if object_id('tempdb..#t') is not null drop table #t;
create table #t
(
filepath nvarchar(300)
);
declare @filePathStr nvarchar(max),
@endIndex int = 1,
@currentFilePath nvarchar(300),
@sql nvarchar(max);
set @filePathStr = '1;235;67456;2667;35;3;67';
set @filePathStr += ';';
while CHARINDEX(';',@filePathStr) > 0
begin
set @endIndex = CHARINDEX(';',@filePathStr) - 1;
print(@endIndex);
set @currentFilePath = SUBSTRING(@filePathStr,1,@endIndex);
print(@currentFilePath);
set @filePathStr = SUBSTRING(@filePathStr,@endIndex + 2,LEN(@filePathStr) - LEN(@currentFilePath));
print(@filePathStr);
insert into #t(filepath)
select @currentFilePath;
end;
select * from #t;
end;
运行后结果截图: