All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
从各种位置截取字符串的SQL语法_[SQL Server教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/3 6:41:57 Browse times: 357 Comment times: 0

从各种位置截取字符串的SQL语法_[SQL Server教程]


Head photo

Go homepage
Upload pictures
Write articles

从各种位置截取字符串的SQL语法_[SQL Server教程]

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





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.