代码如下:
eclare @str nvarchar(50);
set @str='462,464,2';
select @str as '字符串'
select len(@str) as '字符长度'
select charindex(',',@str,1) as '第一个逗号的索引值'
select LEFT(@str,charindex(',1)-1) as '第一个值'
select SUBSTRING(@str,1)+1,len(@str)) as '从第一逗号开始截取出后面的字符串'
select LEFT(SUBSTRING(@str,len(@str)),CHARINDEX(',SUBSTRING(@str,1)-1) as '中间的值'
select SUBSTRING(SUBSTRING(@str,len(@str)) as '最后面的值' --从第二个逗号开始截取出其后的字符串
set @str='462,464,2';
select @str as '字符串'
select len(@str) as '字符长度'
select charindex(',',@str,1) as '第一个逗号的索引值'
select LEFT(@str,charindex(',1)-1) as '第一个值'
select SUBSTRING(@str,1)+1,len(@str)) as '从第一逗号开始截取出后面的字符串'
select LEFT(SUBSTRING(@str,len(@str)),CHARINDEX(',SUBSTRING(@str,1)-1) as '中间的值'
select SUBSTRING(SUBSTRING(@str,len(@str)) as '最后面的值' --从第二个逗号开始截取出其后的字符串