代碼如下:
eclare @str nvarchar(50);
set @str='462,464,2';
select @str as '字符串'
select len(@str) as '字符長(zhǎng)度'
select charindex(',',@str,1) as '第一個(gè)逗號(hào)的索引值'
select LEFT(@str,charindex(',',@str,1)-1) as '第一個(gè)值'
select SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)) as '從第一逗號(hào)開始截取出后面的字符串'
select LEFT(SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)),CHARINDEX(',',SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)),1)-1) as '中間的值'
select SUBSTRING(SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)),charindex(',',SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)),1)+1,len(@str)) as '最后面的值' --從第二個(gè)逗號(hào)開始截取出其后的字符串
更多信息請(qǐng)查看IT技術(shù)專欄