SQL Select everything after character
Using string split available from SQLServer 2016
;with cte
as
(
select
*,row_number() over (order by (select null)) as rownum
from string_split('abcd-efgh-XXXX','-')
)
select top 1 * from cte
order by rownum desc
DECLARE @x varchar(100)
SET @x = 'abcd-efgh-XXXX'
SELECT RIGHT(@x, CHARINDEX('-', REVERSE(@x)) - 1)
You can use:
select right(col, charindex('-', reverse(col)) - 1)