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;
运行后结果截图:
转载于:https://www.cnblogs.com/JimmySeraph/p/11083082.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)