title: SQL Server 2005:charindex starting from the end
body: <p>I have a string 'some.file.name',I want to grab 'some.file'.</p>
  
  <p>To do that,I need to find the last occurrence of '.' in a string.</p>
  
  <p>My solution is :</p>
  
  <pre><code> declare @someStr varchar(20)
  
   declare @reversedStr varchar(20)
  
   declare @index int
  
   set @someStr = '001.002.003'
  
   set @reversedStr = reverse(@someStr)
  
   set @index = len(@someStr) - charindex('.',@reversedStr)
  
   select left(@someStr,@index)
  </code></pre>
  
  <p>Well,isn't it too complicated?I was just intented to using 'some.file' in a where-clause.</p>
  
  <p>Anyone has a good idea? </p>