sql 分割字符串
1.处理一个字符串的并用特定的字符分割获取的值
declare @varstr nvarchar(200)='2,3,5,6'
declare @strindex int
declare @strlastindex int
declare @strvalue nvarchar(13)
while(LEN(@varstr)>0)
begin
set @strindex= charindex(',',@varstr)
if(@strindex=0)
begin
set @strvalue=@varstr
set @varstr=''
end
else
begin
set @strvalue=SUBSTRING(@varstr,0,@strindex)
set @varstr=SUBSTRING(@varstr,@strindex+1,LEN(@varstr)-@strindex)
end
print @strvalue
end