3

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

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

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

2 Answers 2

5

One way:

substring(fld, 6, charindex('\', substring(fld + '\', 6, len(fld))) -1)
Sign up to request clarification or add additional context in comments.

Comments

0
declare @val varchar(100)
set @val = 'Root\FOLDERPATH\somesubfolderpath\somedocument.doc'

select left(right(@val, len(@val) - 5), charindex('\', right(@val, len(@val) - 5)) - 1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.