title: Replace and remove text from string in sql server
body: <p>I have string like the following, it is sample </p>
  
  <pre><code>&lt;b&gt;22/10 - 10:47 - wes:&lt;/b&gt; ###TaskDefId=46###N Enq - Send Quote&lt;b&gt;&lt;br/&gt;29/10 - 15:55 - grn: Some Text ###TaskDefId=31### ABC - DEFG HIJ&lt;b&gt;&lt;br/&gt;22/10 - 12:29 - white: ....
  </code></pre>
  
  <p>Please see below this is the complete string, the original looks like above, I have removed <code>b</code> and <code>br</code> tags to make it more clearer. At the end of each line I have write down that what I want to remove and what I want to replace.</p>
  
  <pre><code>22/10 - 10:47 - wes: ###TaskDefId=46###N Enq - Send Quote               '###TaskDefId=46###N Enq - Send Quote' This should be removed completely 
  29/10 - 15:55 - grn: Some Text ###TaskDefId=31### ABC - DEFG HIJ            '###TaskDefId=31###' This should be replaced with 'STAGE CHNAGED:'
  22/10 - 12:29 - white: Eamiled ###TaskDefId=31### Qtd - Email and Email     '###TaskDefId=31###Qtd - Email and Email' This should be removed completely because last stage was exactly same
  29/10 - 16:26 - wesl: Spoke ###TOaskDefId=48### CTD - DDDDDD            '###TOaskDefId=48###' This should be replaced with 'STAGE CHANGED:' becaue last stage was different
  09/12 - 13:12 - wesl: Spoke ###TaskDefId=31### CTD - DDDDDD         '###TaskDefId=31###' This should be replaced with 'STAGE CHANGED:' becaue last stage was different
  15/11 - 18:41 - white: Some xxxx ###TaskDefId=31### DDD AND - CDD TDED      '###TaskDefId=31###' This should be removed.
  09/12 - 13:12 - wesl: Balanced ###TaskDefId=23### SDTED DERDDW          '###TaskDefId=23###' This should be replaced with 'STAGE CHANGED:'
  </code></pre>
  
  <p>If question looks messy please copy and paste in notepad and I hope the question will make sense. Let me again tell you that this is one string not different rows.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <ol>
  <li><p>This string is in one column of
  table and I need to update the same
  column after these changes.</p></li>
  <li><p>As I have explained in my question
  that I don't just want to replace
  and remove the pattern but replace
  the ###TaskDefId=seomnumber### with
  'STAGE CHANGED:' if last occurrence
  of the pattern and the current one
  is exactly same and removed if last
  occurrence of the pattern and the
  current one is different.</p></li>
  </ol>
  
  <p>Thanks</p>