title: Substring with delimiter in SQL
body: <p>I'm trying to return a substring of the following, it's comma delimited [only one comma]</p>
  
  <pre><code>City-City-City, State-State-State
  </code></pre>
  
  <p>Sometimes it's only one city and state, sometimes it's more than one of either [or  both]</p>
  
  <p>Basically, I need to just return the state initials pass the comma.
  What's the best way to do this? I'm looking into the substring function, but that doesn't seem that smart. I found a split function but it looks like overkill and I don't like to use code I don't understand.</p>
  
  <p>Ex:</p>
  
  <pre><code>Cincinnati-Middletown, OH-KY-IN
  Cleveland-Elyria-Mentor, OH
  Abilene, TX
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>OH-KY-IN
  OH
  TX
  </code></pre>
  
  <p>Thanks for the answers;I just figured it out thanks to Sonam's starting point.
  Here's what I got. Haven't looked into it but it seems to returning the right stuff.</p>
  
  <p><code>select substring(CBSAName,charindex(',',CBSAName)+1, LEN(CBSAName)) FROM CBSAMasterList</code></p>