SQL Select everything after character

coblenski picture coblenski · Aug 16, 2016 · Viewed 60.1k times · Source

I'd like to select everything AFTER a certain character (-) that is placed on the most right side.

Eg.

abcd-efgh-XXXX

And I'd like to select the XXXX part

Thanks!

Answer

Gordon Linoff picture Gordon Linoff · Aug 16, 2016

You can use:

select right(col, charindex('-', reverse(col)) - 1)