码迷,mamicode.com
首页 > 数据库 > 详细

Sql 分割字符串

时间:2015-07-09 19:55:39      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:sqlserver

/*
	分割符为',' 
*/
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

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

Sql 分割字符串

标签:sqlserver

原文地址:http://blog.csdn.net/hu285279904/article/details/46820235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!