sql帶分隔符的截取字符串示例。本站提示廣大學習愛好者:(sql帶分隔符的截取字符串示例)文章只能為提供參考,不一定能成為您想要的結果。以下是sql帶分隔符的截取字符串示例正文
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(',',@str,1)-1) as '第一個值'
select SUBSTRING(@str,charindex(',',@str,1)+1,len(@str)) as '從第一逗號開端截掏出前面的字符串'
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 '最初面的值' --從第二個逗號開端截掏出厥後的字符串