title: Extract folder name right before filename from filepath
body: <p>how can I extract the folder name of a filepath sitting right before the filename?</p>
  
  <p>Example:</p>
  
  <pre><code>declare @a varchar(200)
  set @a = '/path/to/category1/filename.txt'
  select right(@a, charindex('/', reverse(@a)) - 1)
  </code></pre>
  
  <p>this returns filename.txt - In another column I now want to get the "category1" folder name.
  If the path changes to:
   <code>set @b = '/path/to/another/folder/category2/filename.txt'</code>
  it should extract <strong>category2</strong>.</p>