Created
March 8, 2012 11:59
-
-
Save nkostic/2000704 to your computer and use it in GitHub Desktop.
Last Occurance Index in SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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