Sunspl

Hello,everyone,i am sun. 天道酬勤,笨鳥先飛.
随笔 - 47, 文章 - 0, 评论 - 24, 引用 - 0
数据加载中……

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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

posted on 2007-09-16 14:07 JavaSuns 阅读(3909) 评论(3)  编辑  收藏

评论

# re: SQLSERVER字符串截取[未登录]  回复  更多评论   

解决了我碰到的实际问题,非常感谢!!!
2008-11-06 18:23 | user

# SQLSERVER字符串截取  回复  更多评论   

大哥你忒好了!~对我启发很大啊,解决了问题!~
2010-03-18 11:58 | 佳哥

# re: SQLSERVER字符串截取  回复  更多评论   

足下网,http://www.sunspl.com,热烈欢迎您
2010-05-01 19:31 | sunspl.com

只有注册用户登录后才能发表评论。


网站导航: