H-SC
asked on
Extract everything after a certain character
I have a table that has many rows of data like the following ...
abcdefg_524_test_testtest_ 32
4_abcdefg_test_testtest_32
abcdefg_test_testtest_382
abcdefg_test_tes_ttest_32
I need to get the set of numbers after the last "_" in the string. How can this be done?
abcdefg_524_test_testtest_
4_abcdefg_test_testtest_32
abcdefg_test_testtest_382
abcdefg_test_tes_ttest_32
I need to get the set of numbers after the last "_" in the string. How can this be done?
select substring( yourfield, len(yourfield) - charindex('_', reverse(yourfield)) - 1, len(yourfield)
select REVERSE(LEFT(REVERSE(Col),
ASKER
angelIII,
This may work for most of the data, but for some reason a string like : abcdefg_test_testtest_382
brings back "82"
This may work for most of the data, but for some reason a string like : abcdefg_test_testtest_382
brings back "82"
ASKER
ewanqoya,
I ran your sql and keep getting the error :
Invalid length parameter passed to the SUBSTRING function.
I ran your sql and keep getting the error :
Invalid length parameter passed to the SUBSTRING function.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
angelIII,
got it, many thanks works great
got it, many thanks works great
H-SC
I dont use SUBSTRING in my solution
SELECT REVERSE(LEFT(REVERSE(Col),
ASKER
ewanqoya,
hmm, not sure but I indeed still get that exception.
hmm, not sure but I indeed still get that exception.
Very interesting
But angelIII's solution works for you already
ASKER
ewanqoya,
I know, I just like to follow up with everyone who responds to the post out of respect. many thanks for your help here as well. take care :)
I know, I just like to follow up with everyone who responds to the post out of respect. many thanks for your help here as well. take care :)