title: C# - SQL WITH clause
body: <p>Just fishing for ideas-</p>
  
  <p>I have a SQL statement that I need to parse in C#. It is formatted basically as follows -</p>
  
  <pre><code>    WITH TableX as (
  
      -- something else could be here..
      select field1, field2, .. fieldX
      from mytable
      -- something else could be here..
  
      )
  
      -- something else could be here..
      select /*THESE FIELDS ARE BEING REPLACED*/ TableX.field1, TableX.field2, .. TableX.fieldX
      from TableX
      -- something else could be here.. ie, more joins, selecting from subqueries. Basically another select could exist here.
  </code></pre>
  
  <p>Any ideas on how to replace "TableX.field1, TableX.field2, .. TableX.fieldX" with another group of field guaranteed to be in the result set?</p>