title: SQL select data between two characters in a string
body: <p>I have data shown below. I'd like to retrieve the data between the underscores. The data either side of the underscore can be any length. I am select this data from a table with thousands of rows and will be amount other data being selected in the overall query. Can anyone help please.</p>
  
  <p>Column name is d.ThirdPartyRef </p>
  
  <pre><code>2500_NEW_001
  </code></pre>
  
  <p>I have already selected the data from the left of the above field for another column using the below.</p>
  
  <pre><code>substring(d.ThirdPartyRef, 1, charindex('_', d.ThirdPartyRef)-1) as CarrierCode_DayNumber
  </code></pre>
  
  <p>Thanks</p>