0

I have list of file path stored in a column of a table. Now I need to extract only till last '\' in file path (i.e like below result set) Example:

column_A
--------------
G:\REPORTS\DDMS\PCP0.txt
G:\REPORTS\DPS\DEFAU.pdf

Result

G:\REPORTS\DDMS\
G:\REPORTS\DPS\
1
  • 3
    What did you try so far? Commented Jan 22, 2015 at 9:58

3 Answers 3

3

Try this.

DECLARE @str VARCHAR(500)='G:\REPORTS\DDMS\PCP0.txt'

SELECT Reverse(Substring(Reverse(@str), Charindex('\', Reverse(@str)), Len(@str))) 
Sign up to request clarification or add additional context in comments.

Comments

0

If you are working with .net , http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.110).aspx Path.GetFileName will parse that for you.

1 Comment

.Net is available in SQL Server and this kind or processing is arguably done best in SQLCLR.
0

Try this

DECLARE @str VARCHAR(500)='G:\REPORTS\DDMS\PCP0.txt'

SELECT LEFT(@str, len(@str) - CHARINDEX('\', REVERSE(@str))) 

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.