I need to extract multiple strings between 2 specific characters that repeats several times in a row. for example; these are 2 rows from my table:
id myString
One method uses recursive CTEs:
with cte as (
select id,
left(stuff(myString, 1, charindex('(', myString), ''),
charindex(')', myString) - charindex('(', myString) - 1
) as val,
stuff(myString, 1, charindex(')', myString) + 1) as rest
from t
where myString like '%(%)%'
union all
select id,
left(stuff(rest, 1, charindex('(', rest), ''),
charindex(')', rest) - charindex('(', rest) - 1
) as val,
stuff(rest, 1, charindex(')', myString) + 1) as rest
from cte
where rest like '%(%)%'
)
select id, val
from cte;