title: Invalid length parameter passed to the SUBSTRING function error
body: <p>I have the following T-SQL query which works fine:</p>
  
  <pre><code>declare @myString varchar(max) = 'Import Development \ local \ Jan
  2016 \ Jenny Asti \ reimbur.docx'  
  
  select substring((@myString), 1, len(@myString) - charindex('\', reverse (@myString)))
  </code></pre>
  
  <p>I am looking to return the string before the last backslash and and I am correctly getting this:         </p>
  
  <p><code>Testing Development \ local \ Jan 2016 \ Jenny Asti</code> </p>
  
  <p>However, I need to run this command for a table and not using a variable. So, I've changed to the following:</p>
  
  <pre><code>select substring([path], 1, len(path)- charindex('\',reverse(path))) from test
  </code></pre>
  
  <p>But I get an error: <code>Invalid length parameter passed to the SUBSTRING function.</code></p>
  
  <p>I can confirm that the <code>\</code> does exist in the table. Also, if I look at the results windows, the query is able to list this: </p>
  
  <blockquote>
    <p>Import Development \ local \ Jan 2016 \ Jenny</p>
  </blockquote>
  
  <p>I believe there is something wrong parsing the last part of the string 
  <code>Asti \ reimbur.docx</code>.</p>