Solved

REPLACE a certain string in a certain field

Posted on 2014-04-15
2
191 Views
Last Modified: 2014-04-15
Hi there,

I have hundreds of  text strings in a specific field of a certain table with none or exactly these two "words": <semantics> and  </semantics>

I want to REPLACE the whole string presented, BUT excluding the two above "words" present at them, if it is the case.

Example: one possible data contained in the field is:

<p>Question 06: If  <math>   <semantics>    <mrow>     <mtext>&#8201;</mtext><mtext>&#8201;</mtext><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mi>a</mi><mtext>&#8201;</mtext><mtext>&#8201;</mtext><mtext>&#8201;</mtext>    </mrow>    <annotation encoding='MathType-MTEF'>MathType@MTEF@5@5@+=feaagCart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbwvMCKfMBHbqedmvETj2BSbqefm0B1jxALjhiov2DaerbuLwBLnhiov2DGi1BTfMBaebbnrfifHhDYfgasaacH84rpq0xbbf9q8WrFfeuY=Hhbbf9v8qqGqFr0xc9LqFj0lXxbba9Lqpepi0xhr=Fc9vqpeuj0lXdb9GqFj0dd9qqaqpi0xe9Gq=Fhrpe0dc8meaabaqaciaacaGaaeqabaWaaqaafaaakeaacaaMc8UaaGPaVlaadIhacqGHRaWkcaWG5bGaeyypa0JaamyyaiaaykW7caaMc8UaaGPaVdaa@46B9@</annotation>   </semantics>  </math> </p>

And I want to have it substituted by this one:

<p>Question 06: If  <math>    <mrow>     <mtext>&#8201;</mtext><mtext>&#8201;</mtext><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mi>a</mi><mtext>&#8201;</mtext><mtext>&#8201;</mtext><mtext>&#8201;</mtext>    </mrow>    <annotation encoding='MathType-MTEF'>MathType@MTEF@5@5@+=feaagCart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbwvMCKfMBHbqedmvETj2BSbqefm0B1jxALjhiov2DaerbuLwBLnhiov2DGi1BTfMBaebbnrfifHhDYfgasaacH84rpq0xbbf9q8WrFfeuY=Hhbbf9v8qqGqFr0xc9LqFj0lXxbba9Lqpepi0xhr=Fc9vqpeuj0lXdb9GqFj0dd9qqaqpi0xe9Gq=Fhrpe0dc8meaabaqaciaacaGaaeqabaWaaqaafaaakeaacaaMc8UaaGPaVlaadIhacqGHRaWkcaWG5bGaeyypa0JaamyyaiaaykW7caaMc8UaaGPaVdaa@46B9@</annotation>  </math> </p>

(Of course the bold ... is present only here, for the sake of clearness.)

Thanks,
fskilnik.
0
Comment
Question by:fskilnik
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40001640
update table
set field = replace(replace(field, '<semantics>', ''), '</semantics>', '')

to test it out and make sure this is what you want:

select replace(replace(field, '<semantics>', ''), '</semantics>', '')
from table
0
 

Author Closing Comment

by:fskilnik
ID: 40001697
Perfect, Kyle! Thanks a lot.

Regards,
fskilnik.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question