This is the basic structure of some strings in a column:
CREATE TABLE #M(ST VARCHAR(250));
INSERT INTO #M
values
('please help me world (produced... but needs to go)'),
('please help me world Y (produced_this is extra extra extra long)'),
('please help me world Z (producedthis isshort)'),
('please help me world K (produced');
SELECT *
FROM #M;
What I need to do is extract this `(produced%)' whenever it is found.
I can find occurrences of rows with the offending snippet `(produced%)' easily enough viathis:
SELECT *
FROM #M
WHERE ST LIKE '%(PRODUCED%)%'
What I now need to do is delete the section from (produced
up to the very next brace )
- as you can see the distance between these two phrases is variable.
After querying I'd hope to have the following results:
'please help me world X'
'please help me world Y'
'please help me world Z'
'please help me world K (produced'
Because there is no closing brace in the 4th statement it is left as is.
EDIT
There could be text to the right of the offending phrase - so a better example of some strings is the following:
CREATE TABLE #M(ST VARCHAR(250));
INSERT INTO #M
values
('please help me world (produced... but needs to go) bb cc dd'),
('please help me world Y (produced_this is extra extra extra long)'),
('please help me world Z (producedthis isshort)'.xlsm),
('please help me world K (produced');