0

Using Management Studio 2012, I have a field which holds paths to files

C:/Documents/FolderA/FolderA1/FileName1
C:/Documents/FolderA/FolderA1/FileName2
C:/Documents/FolderA/FolderA1/FileName3
C:/Documents/FolderA/FileNameA
C:/Documents/FolderA/FileNameB

Want my field to look like this

C:/Documents/FolderA/FolderA1/
C:/Documents/FolderA/FolderA1/
C:/Documents/FolderA/FolderA1/
C:/Documents/FolderA/
C:/Documents/FolderA/

Have tried using the function left but you have to declare the amount of characters to get to delete and obviously some file name are longer than others so this doesn't work.

Yogesh Sharma
  • 47,987
  • 5
  • 21
  • 48
Clem_Fandango
  • 242
  • 1
  • 14
  • This might be helpful https://stackoverflow.com/questions/39002025/is-there-a-lastindexof-in-sql-server – apomene Sep 20 '18 at 10:37

1 Answers1

0

You can do :

select col, replace(col, right(col, charindex('/', reverse(col) + '/' ) -1), '')
from table t;

This assumes Folders always contains filenames.

Yogesh Sharma
  • 47,987
  • 5
  • 21
  • 48