title: Is there a LastIndexOf in SQL Server?
body: <p>I am trying to parse out a value from a string that involves getting the <a href="https://stackoverflow.com/questions/15709712/what-is-best-way-to-get-last-indexof-character-in-sql-2008">last</a> <a href="https://stackoverflow.com/questions/1024978/find-index-of-last-occurrence-of-a-sub-string-using-t-sql">index</a> of a <a href="http://www.sqlmatters.com/Articles/Searching%20a%20string%20for%20the%20last%20occurrence%20of%20a%20given%20string.aspx" rel="noreferrer">string</a>.  Currently, I am doing a horrible hack that involves reversing a string:</p>
  
  <pre><code>SELECT REVERSE(SUBSTRING(REVERSE(DB_NAME()), 1, 
      CHARINDEX('_', REVERSE(DB_NAME()), 1) - 1))
  </code></pre>
  
  <p>To me this code is nearly unreadable.  I just upgraded to SQL Server 2016 and I hoping there is a better way.
  Is there?</p>