title: Get Last Word from String in Table
body: <p>I am attempting to get the last word from table <code>Project</code> in SQL-Server 2017.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>select 
  reverse(substring(reverse(ProjectDescription),1, charindex(' ', reverse(ProjectDescription)) -1)) as LastWord
  from Project 
  </code></pre>
  
  <p>The code works if I ask isolate the table to a single line, but I need the last word for all lines in the field <code>ProjectDescription</code>.</p>
  
  <p>When I run the code as above, I get the following error:</p>
  
  <blockquote>
    <p>Invalid length parameter passed to the LEFT or SUBSTRING function.</p>
  </blockquote>
  
  <p>Please can someone assist me on where I am going wrong. </p>