find characters after a certain character

declare @Find varchar(20)
declare @search varchar(50)
SET @Find=’- ‘
SET @Search=’hhhjoehhh-joehhhjoex- 02340’
SELECT COALESCE(RIGHT(@search, NullIf(CHARINDEX(REVERSE(@Find), REVERSE(@search)), 0)-1), @search)

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.