sql server 截取字符串

wendaoshuangyue 2009-07-16 03:31:40
例如字段path=‘E:\resin\resin\webapps\newsystem\’ 我想把这个字段的值从倒数第三个‘\’开始截取为‘\webapps\newsystem\’,请问在数据库中该怎么写这个sql啊?
...全文
108 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
plglenn7 2009-07-17
  • 打赏
  • 举报
回复
d
  • 打赏
  • 举报
回复
呵呵。简单问题,而且又很典型。

所以回答的也很典型。
htl258_Tony 2009-07-17
  • 打赏
  • 举报
回复
DECLARE @S NVARCHAR(100) 
SET @S= 'E:\RESIN\RESIN\WEBAPPS\NEWSYSTEM\'
SELECT RIGHT(@S,CHARINDEX('\',REVERSE(@S),CHARINDEX('\',REVERSE(@S),CHARINDEX('\',REVERSE(@S))+1)+1))
/*

----------------------------------------------------------------------------------------------------
\WEBAPPS\NEWSYSTEM\

(1 行受影响)
*/
claro 2009-07-17
  • 打赏
  • 举报
回复
帮顶
ChinaJiaBing 2009-07-16
  • 打赏
  • 举报
回复

declare @path nvarchar(100)
set @path='E:\resin\resin\webapps\newsystem\'
select SUBSTRING(@path,CHARINDEX('\',@path,10),CHARINDEX('\',@path,25))


rutstyle 2009-07-16
  • 打赏
  • 举报
回复
被牛人们扫荡过的贴了。。
Cyanapple_wen 2009-07-16
  • 打赏
  • 举报
回复
DECLARE @S NVARCHAR(100) = 'E:\resin\resin\webapps\newsystem\'
select substring(@S,charindex('\',@S,charindex('\',@S,charindex('\',@S)+1)+1),len(@S))
Tomzzu 2009-07-16
  • 打赏
  • 举报
回复

--------------------------------------------------------------------------------
\webapps\newsystem\

(所影响的行数为 1 行)
Tomzzu 2009-07-16
  • 打赏
  • 举报
回复

declare @s varchar(80)
set @s = 'E:\resin\resin\webapps\newsystem\'
select substring( @s, len(@s)-charindex('\', reverse(@s), charindex('\', reverse(@s), charindex('\', reverse(@s))+1)+1)+1, len(@s) )
feixianxxx 2009-07-16
  • 打赏
  • 举报
回复
DECLARE @a VARCHAR(100)
SET @a='E:\resin\resin\webapps\newsystem\'
select stuff(@a,1,len(@a)-charindex('\',REVERSE(@a),charindex('\',REVERSE(@a),charindex('\',REVERSE(@a))+1)+1),'')




----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\webapps\newsystem\
wendaoshuangyue 2009-07-16
  • 打赏
  • 举报
回复
不对啊,哥们,我想要的是‘\webapps\newsystem\’,不是‘\resin\webapps\newsystem\
jiangshun 2009-07-16
  • 打赏
  • 举报
回复
declare @s varchar(80)
set @s='E:\resin\resin\webapps\newsystem\'
select right(@s,charindex('\',REVERSE(@s),charindex('\',REVERSE(@s),charindex('\',REVERSE(@s),charindex('\',REVERSE(@s))+1)+1)+1))

/*

--------------------------------------------------------------------------------
\resin\webapps\newsystem\

(所影响的行数为 1 行)


*/
jiangshun 2009-07-16
  • 打赏
  • 举报
回复
declare @s varchar(80)
set @s='E:\resin\resin\webapps\newsystem'
select right(@s,charindex('\',REVERSE(@s),charindex('\',REVERSE(@s),charindex('\',REVERSE(@s))+1)+1))

/*

--------------------------------------------------------------------------------
\resin\webapps\newsystem

(所影响的行数为 1 行)

*/

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧