I need to pick out some string from a string that varies in length.
The end result is to pick out the id number, contained in brackets, from a string.
An example of the data is:
Jones (4)
Smith (Deceased) (100)
The Result from the above example would need to be:
4
100
Ideally I want a query that will find the start position of the last open bracket and pick up the data from that point onwards, because the id number, contained in brackets, is always at the end.
INSTR(contact_data,'(',1,2)
gives me the start point, but requires me to provide the nth occurrence - which is a variable because some data contains 1 bracket, some contain more.
I have tried to introduce a variable into occurrences, but it errors - please see below and please help if you can!
SELECT * FROM OPENQUERY(PROCLAIM,'
SELECT a.contact_data,
INSTR(a.contact_data,''('',1,a.bracket_occurrences) AS searching_for_start_point,
SUBSTRING(a.contact_data,LOCATE(''('',a.contact_data,1)+1,LENGTH(a.contact_data)-LOCATE(''('',a.contact_data,1)-1) AS contact_id
FROM(
SELECT contact_data,
CAST(LENGTH(contact_data) - LENGTH(REPLACE(contact_data,''('','''')) AS INT) AS bracket_occurrences
FROM PUB.contacts
) AS a
')
Unfortunately, I only have access to a very limited set of SQL commands as I am using Progress OpenEdge.
Below is a partial link to the functions I have access to if you want to have a look: documentation.progress .com /output /OpenEdge117 /openedge117 /#page /dmsrf%2Fopenedge-sql-functions.html%23