t-sql 子串 [英] t-sql substring

查看:32
本文介绍了t-sql 子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上有一列需要子串.列的格式如下所示:

I basically have one column that needs to be substringed. The format of the column looks as follow:

Column A
--------
Root\FOLDERPATH\somesubfolderpath\somedocument.doc

第一个字符串Root\"将总是具有相同字符的相同长度.Root\"之后的所有内容的长度都可能因文档的文件夹结构而异.

The first string "Root\" will always be the same lengt with same characters. Everything after the "Root\" could vary in lenght depending on the document's folder structure.

我需要检索的是第二个字符串.使用上面的示例,该列应该看起来像:

What I need to retrieve is the second string. Using the above example, the column should look lilke:

Column A
--------
FOLDERPATH

所以我需要剪掉Root\"获得这之后的字符串并剪掉之后的所有内容.

So I need to cut out the "Root\" obtain the string after this and cut out everything after this.

推荐答案

一种方式:

substring(fld, 6, charindex('\', substring(fld + '\', 6, len(fld))) -1)

这篇关于t-sql 子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆