title: SQL replace WHERE clause
body: <p>We have the below query which was written to replace any &amp; in a memo field with the HTML equivalent (&amp;). When written, we did not consider that there are potentially other HTML tags in the field which also begin with “&amp;” (i.e. &mdash; &quot; etc). Since we must ensure that all ampersands are the HTML equivalent when used alone and not part of another tag we must skip those which at part of another tag. That said, the shortest HTML tag which can start with &amp; seems to be 3 characters, and the longest seems to be six characters, so &amp; _ _ _ ; to &amp; _ _ _ _ _ _ ; in length ... are there any ideas on updating the where clause so that it does not update any &amp; which are proceeded with a ";" in the next 4-7 characters after a &amp;? Thank you.</p>
  
  <pre><code> UPDATE STOCKMEM
   SET INETFDESC = CAST(
                         REPLACE(
                                 REPLACE(
                                         CAST(INETFDESC as NVarchar(MAX))
                                 ,'&amp;amp;','&amp;')
                         , '&amp;', ,'&amp;amp;')AS NText)
    WHERE INETFDESC LIKE '%&amp;[^amp;]%' 
  </code></pre>