title: Working with Charindex and right function when the value is null
body: <p>Basically I am trying to get a file name from a column that captures the whole path.  Below   select statement actually worked before the database got refreshed.  Now it is failing because there are no files uploaded recently.</p>
  
  <p>Here is the error I am getting: 
  Error: Invalid length parameter passed to the RIGHT function.</p>
  
  <pre><code>SELECT right(batch_ID, CHARINDEX('\', REVERSE(batch_ID)) - 1) AS [File Name]
  from
  table1
  </code></pre>
  
  <p>Please help me figure out how to change the statement so if there is a null value or if charindex cannot find '\' it would still work.</p>
  
  <p>Thanks!</p>