title: T-SQL split string based on delimiter
body: <p>I have some data that I would like to split based on a delimiter that may or may not exist.</p>
  <p>Example data:</p>
  <pre><code>John/Smith
  Jane/Doe
  Steve
  Bob/Johnson
  </code></pre>
  <p>I am using the following code to split this data into First and Last names:</p>
  <pre><code>SELECT SUBSTRING(myColumn, 1, CHARINDEX('/', myColumn)-1) AS FirstName,
         SUBSTRING(myColumn, CHARINDEX('/', myColumn) + 1, 1000) AS LastName
  FROM   MyTable
  </code></pre>
  <p>The results I would like:</p>
  <pre><code>FirstName---LastName
  John--------Smith
  Jane--------Doe
  Steve-------NULL
  Bob---------Johnson
  </code></pre>
  <p>This code works just fine as long as all the rows have the anticipated delimiter, but errors out when a row does not:</p>
  <pre><code>&quot;Invalid length parameter passed to the LEFT or SUBSTRING function.&quot;
  </code></pre>
  <p>How can I re-write this to work properly?</p>