当前位置: 数据库>sqlserver
sqlserver中遍历字符串的sql语句
来源: 互联网 发布时间:2014-10-09
本文导语: 代码如下: declare @ddd varchar(50),@split varchar(1) set @ddd = '12345678,1234567890,1234567890,123456,123456789' set @split = ',' while(charindex(@split,@ddd)0) begin select substring(@ddd,1,charindex(@split,@ddd)-1) set @ddd = stuff(@ddd,1,charindex(@split,@ddd),'') select @ddd end
代码如下:
declare @ddd varchar(50),@split varchar(1)
set @ddd = '12345678,1234567890,1234567890,123456,123456789'
set @split = ','
while(charindex(@split,@ddd)0)
begin
select substring(@ddd,1,charindex(@split,@ddd)-1)
set @ddd = stuff(@ddd,1,charindex(@split,@ddd),'')
select @ddd
end