John Cobby John Cobby - 3 months ago 26
SQL Question

SQL Select everything after character

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

You can use:

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