user3219693
user3219693

Reputation: 201

T-SQL Select values from the end of a string which are between 2 characters

I have tried looking in to Reverse and CharIndex but I just can't seem to get it to work.

I have a table with a column full of strings, all of which end with aVALUESa

The VALUES are a number and vary in length, how do I select these values?

Upvotes: 3

Views: 71

Answers (1)

shree.pat18
shree.pat18

Reputation: 21757

Assuming that your strings always end with the pattern 'aVALUESa' where the 'a' at the start and end is the literal 'a', you can try this:

select reverse(substring(reverse(colname),2,charindex('a',reverse(colname),2)-2))
from yourtable

Upvotes: 1

Related Questions