存储过程中分隔循环处理,用于批量操作数据
declare @tem varchar(300)
declare @Index int
set @tem='1,12,22,13,33,'
declare @Count int
set @Count = 1
set @Index = charindex(',',@tem)
while @Index > 0
begin
select substring(@tem,@Count,@Index - @Count)
set @Count = @Index + 1
set @Index = charindex(',',@tem,@Count)
end
declare @Index int
set @tem='1,12,22,13,33,'
declare @Count int
set @Count = 1
set @Index = charindex(',',@tem)
while @Index > 0
begin
select substring(@tem,@Count,@Index - @Count)
set @Count = @Index + 1
set @Index = charindex(',',@tem,@Count)
end