0

I have a string like

`...<..../><... id='someID' .../><...../>....` 

(the total length of that string is more than 15k chars, it's an XML form definition)

Inside of that string I have the someID value. I want to put after the element containing that value a new string:

...<..../><... id='someID' .../><my_new_string><...../>....

I tried to split that long string basing on the someID value, but that approach is too slow. How can I achieve that on the other way ?

Or maybe is it possible to select the substring <... id='someID' .../> ?

3 Answers 3

1

SQL server can work with XML. You do not need to use substring. A simular problem was solved on this page: xml.modify

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried using Replace? For example:

REPLACE(yourString, yourPattern, yourPattern + newString);

Using your example, it would look something like:

REPLACE('...<..../><... id='someID' .../><...../>....',
        '<... id=''someID'' .../>',
        '<... id=''someID'' .../><my_new_string>');

Please notice I escaped the ' characters around "someID".

Best regards.

Comments

0

It isn't clear what data type your string is: xml or (n)varchar? For xml, you can use the various data type methods; for (n)varchar the STUFF() function inserts one string into another string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.