title: Extracting First Name and Last Name
body: <p>I have a column named Name in a table called test which has Full name and I am trying to extract First name and Last Name. So I wrote query something like this:</p>
  
  <pre><code>SELECT 
  [Name],
   LEFT([Name],CHARINDEX(' ',[Name])-1)  AS FIRST_NAME,
  SUBSTRING([Name],CHARINDEX(' ',[Name])+1,LEN([Name])) AS LAST_NAME
  FROM Test
  </code></pre>
  
  <p>But It is giving me error saying:</p>
  
  <p>Msg 537, Level 16, State 2, Line 1
  Invalid length parameter passed to the LEFT or SUBSTRING function.</p>
  
  <p>Thta's because I have some values in the name like:</p>
  
  <p>Name:</p>
  
  <p>Hopkins</p>
  
  <p>How do I handle these? </p>