欢迎投稿

今日深度:

Sql 分割字符串,sql分割字符串

Sql 分割字符串,sql分割字符串


/*
	分割符为',' 
*/
declare @depid varchar(100)
declare @location int
declare @length int
--示例字符串
set @depid = '13434,32,34,567,12,9998,'
set @location = 1
set @length = 0
while @location <> 0
begin
	set @location = charindex(',', @depid, @location)
	if @location = 0 
	begin
		break;
	end
	else 
	begin
		--print @location
		--print @length
		print SUBSTRING(@depid,@location - (@location - 1 - @length),@location - 1 - @length)
		set @location = @location + 1
		set @length = (@location - 1)
	end
end 


运行结果

13434
32
34
567
12
9998

版权声明:本文为博主原创文章,未经博主允许不得转载。

www.htsjk.Com true http://www.htsjk.com/shujukunews/9271.html NewsArticle Sql 分割字符串,sql分割字符串 /*分割符为, */declare @depid varchar(100)declare @location intdeclare @length int--示例字符串set @depid = 13434,32,34,567,12,9998,set @location = 1set @length = 0while @location 0beginset @l...
评论暂时关闭