title: SQL Server substring
body: <p>I need a good expression in order to select correctly parts of a field.
  For example, the field can be of the type: "google_organic" or "google_campaign_HereGoesMyCode" . The part I am interested in is "organic" or "campaign" without any other addition.
  So far I select with this:</p>
  
  <pre><code> substring(Referer, charIndex('_',Referer)+1, len(Referer))
  </code></pre>
  
  <p>But in the case of "campaign" I select the whole thing... I don't know how to manage the existence or non-existence of the second underscore...</p>
  
  <p>thank you</p>