Reputation: 3491
I have a Table in my database in SQL. This table has a column by this name : Title
Values of this column is : A + B + CC
, D + EEE
, F + G + H + I
, HHHH
I need to split this values and select last index of this values.
How can I select this result : CC
, EEE
, I
, HHHH
?
Upvotes: 0
Views: 1440
Reputation: 51514
select
right(Title,case CHARINDEX('+',reverse(Title)) when 0 then LEN(Title) else CHARINDEX('+',reverse(Title))-1 end )
Upvotes: 2
Reputation: 1271121
Presumably, the letters can be more than one character. For this, you need reverse and charindex:
select (case when charindex('+', title) > 0
then right(title, charindex('+', reverse(title))-1)
else title
end) as lastone
Upvotes: 6