已知: 字段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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
新闻热点
疑难解答