title: Invalid length parameter passed to the RIGHT function MESSAGE
body: <p>I have an issue. I am running a name parsing script on a file that is 87 million rows. It is set up to parse the <code>NAME</code> column, which has data in it such as SMITH, STEVE S, and so on.</p>
  
  <p>When I run the below command to break up the name into columns firstname, middlename and lastname, which works in all my other tables but this stubborn one, I get this error:</p>
  
  <blockquote>
    <p>Invalid length parameter passed to the RIGHT function</p>
  </blockquote>
  
  <p>Not really sure why. Please any help would be great.</p>
  
  <pre><code>UPDATE table6
      SET lastName = LEFT(Name, CHARINDEX(', ', Name) - 1), 
          firstname = SUBSTRING(Name, CHARINDEX(', ', Name) + 2, CASE WHEN CHARINDEX(' ', Name, CHARINDEX(', ', Name) + 2) = 0 THEN LEN(Name) + 1 ELSE CHARINDEX(' ', Name, CHARINDEX(', ', Name) + 2) END - CHARINDEX(', ', Name) - 2),
          middlename = RIGHT(Name, LEN(Name) - CASE WHEN CHARINDEX(' ', Name, CHARINDEX(', ', Name) + 2) = 0 THEN LEN(Name) ELSE CHARINDEX(' ', Name, CHARINDEX(', ', Name) + 2) END) 
  </code></pre>