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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【编辑推荐】