title: SQL I need multiple cases for one column
body: <p>My previous question was - <a href="https://stackoverflow.com/questions/12746573/insert-substring-into-new-column">insert substring into new column</a></p>
  
  <p>I have two cases I want to run on the same column.</p>
  
  <p>The first -  </p>
  
  <pre><code>SET [ref_id] = CASE 
  WHEN CHARINDEX('-', [full_id]) = 4 
  THEN SUBSTRING([full_id], 1, 3) ELSE NULL
  </code></pre>
  
  <p>The second - </p>
  
  <pre><code>SET [ref_id] = CASE 
  WHEN CHARINDEX('ZZZ-', [full_id]) = 1 
  THEN SUBSTRING([full_id], 5, 3) ELSE NULL
  </code></pre>
  
  <p>My <code>[full_id]</code> column data format is mainly <code>ABC-123D2-45FG67</code> BUT some of it is all numbers or is prefixed with <code>ZZZ-</code> </p>
  
  <p>If the data is only numbers I want the <code>[ref_id]</code> column to be NULL.</p>
  
  <p>If the data is prefixed with <code>ZZZ-</code> I want that part to be skipped.</p>
  
  <p>If the data is not <code>ZZZ-</code> and starts with <code>ABC-</code> I want to copy the <code>ABC</code> (in some cases there is <code>AB-1234</code> and that should be NULL).</p>
  
  <p>My code works fine except that the two strings do not function together and when I run them separately they cancel out the work of the previous query.</p>
  
  <p>How can I run both and end up with NULLS only for the data in formats like <code>123456</code> and <code>AB-1234</code> </p>
  
  <p>Thank you for the help.</p>