Search code examples
sql-serverfunctionsubstringcharindex

how to find Second char from a special char in sql


i have this= 'student 1-99-98 - 281 - 1567519464' an this length is dynamic i want Phrase of after last '-' i want to extract this='1567519464' please help me in Microsoft SQL query


Solution

  • SELECT Ltrim(rtrim(RIGHT('student 1-99-98 - 281 - 1567519464', (CHARINDEX('-',REVERSE('student 1-99-98 - 281 - 1567519464'),0)-1))))