<b>sql server字符串截取实例解析</b>[MSSQL防范]
本文“<b>sql server字符串截取实例解析</b>[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
sql server字符串的截取办法大概很多人还不知道,下面就以一个例子来为您介绍sql server字符串截取的办法,供您参考,但愿对您能有所启迪.
已知: 字段A='F:\photo\Winter Leaves.jpg'
要求:分段截取每段字符[字段A不能为TEXT范例,不然报错]
办理办法:
+++++++++++++++++++++++++++++++++++++++++++++++++++
---截取sql server字符串A的第一个\左边的字符串
select left(A,charindex('/',A)-1)
输出后果:F:
++++++++++++++++++++++++++++++++++++++++++++++++++++
---截取\中间的字符串
select left(stuff(A,1,charindex('/',A),''),charindex('/',stuff(A,1,charindex('/',A),''))-1)
输出后果:photo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
---截取最后一个\背面的sql server字符串
select reverse(left(reverse(A),charindex('/',reverse(A))-1))
输出后果:Winter Leaves.jpg
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
---截取字符串A的首字幕
select STUFF(A,1, 1, '')
输出后果::\photo\Winter Leaves.jpg
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以上是“<b>sql server字符串截取实例解析</b>[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |