title: TSQL: Update values by using With statement?
body: <p>I have a table with a column I would like to update its values. Here is an example of TSQL codes:</p>
  
  <pre><code>WITH Pieces(id, newdesc) AS
  (
  SELECT itemid, REPLACE(REPLACE(description, 'DESC_A', 'DESC_B'), 'NEW_1', 'NEW_2')
    FROM myTable
    WHERE description like '%DESC_A%DESC_B%'
  )
  -- SELECT * FROM Pieces
  UPDATE myTable SET description = newdesc // not working, how?
  </code></pre>
  
  <p>This update is NOT working. By commenting out SELECT, I can see the result is what I need. How I can do this change in a batch way for a group of rows? Not sure is it possible by WITH statement?</p>
  
  <p>Here are some example data:</p>
  
  <pre><code>....
  xxxDESC_AyyyDESC_Bwwww
  aaaDESC_AxxDESC_Beee
  ....
  </code></pre>
  
  <p>the udpated ones will be:</p>
  
  <pre><code>....
  xxxNEW_1yyyNEW_2wwww
  aaaNEW_1xxNEW_2eee
  ....
  </code></pre>