SQLSERVER字符串截取

已知: 字段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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 ---截取字符串A的首字幕
select  STUFF(A,1, 1, '')
输出结果::/photo/Winter Leaves.jpg
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

---截取字符串中最后一个字符-前面的字符
pronum2='A-4-1-8-1'
substring(pronum2,1,len(pronum2)-len('-'+reverse(left(reverse(pronum2),charindex('-',reverse(pronum2))-1))))
输出结果:'A-4-1-8
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值