加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql带分隔符的截取字符串示例

发布时间:2020-12-12 09:24:17 所属栏目:MsSql教程 来源:网络整理
导读:代码如下: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)+

代码如下: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 '最后面的值' --从第二个逗号开始截取出其后的字符串

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读