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!
Use the SUBSTRING() function. The first argument is the string or the column name. The second argument is the index of the character at which the substring should begin. The third argument is the length of the substring.
You can use:
select right(col, charindex('-', reverse(col)) - 1)
DECLARE @x varchar(100) SET @x = 'abcd-efgh-XXXX' SELECT RIGHT(@x, CHARINDEX('-', REVERSE(@x)) - 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With