Skip to content

Instantly share code, notes, and snippets.

@nkostic
Created March 8, 2012 11:59
Show Gist options
  • Save nkostic/2000704 to your computer and use it in GitHub Desktop.
Save nkostic/2000704 to your computer and use it in GitHub Desktop.
Last Occurance Index in SQL
declare @SomeString varchar(30)
set @SomeString='ABC-AB-B-ABC-ABCD-0001-001-X'
-- We are searching for last occurrence of '-' in @SomeString
select LEN(@SomeString)-(CHARINDEX('-',REVERSE(@SomeString))) as LastOccuranceIndex
--LastOccuranceIndex should return 26 :P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment