首页 > 开发 > 综合 > 正文

SQLSERVER字符串截取

2024-07-21 02:11:42
字体:
来源:转载
供稿:网友

已知: 字段a='f:/photo/winter leaves.jpg'  
要求:分段截取每段字符[字段a不能为text类型,否则报错]
解决方法:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


---截取字符串a的第一个/左边的字符串
select left(a,charindex('/',a)-1)
输出结果:f:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

---截取/中间的字符串
select  left(stuff(a,1,charindex('/',a),''),charindex('/',stuff(a,1,charindex('/',a),''))-1)
输出结果:photo
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


---截取最后一个/后面的字符串
select  reverse(left(reverse(a),charindex('/',reverse(a))-1))
输出结果:winter leaves.jpg
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表