0

I have a column with a folder path structure

root01/folder01/sub-folder  
root01/folder2/subfolder  
root2/folder01/anothersub/evenmore  
root2/folder400/anothersub  

Ideally I'd like a query that would return the 2nd to last folder, like

folder01  
folder2  
anothersub  
folder400  

I'd also be happy with the path, up to the last level

root01/folder01  
root01/folder2  
etc...
katzu
  • 3
  • 2
  • Does it have to be a pure SQL solution? Or could you perform string manip on the results with whatever language you are processing the results with? – s3lph Apr 01 '15 at 21:21
  • It does need to be purely sql. I'm not processing the results beyond the output I get from sql – katzu Apr 01 '15 at 21:37
  • So you're just entering queries and look at the results? You don't process the results for display? – s3lph Apr 01 '15 at 21:53
  • right this second, yes. but once I get it right there, they'll be output as a csv – katzu Apr 01 '15 at 22:04
  • And how do you bring them into a CSV format? I'd do the string manipulation when putting the results into the CSV – s3lph Apr 01 '15 at 22:36
  • The packaging to csv happens in the backend of third party software that I don't have access to. – katzu Apr 02 '15 at 18:48

1 Answers1

0

try this :

SELECT PARSENAME(REPLACE('root01/folder01/sub-folder', '/', '.'), 2) 

as this solution works on sql server2005 for more information click here

Community
  • 1
  • 1
Modar Na
  • 49
  • 4