title: t-sql WITH on WITH
body: <p>I have to make query on WITH query, something like</p>
  
  <pre><code>; WITH #table1  
  (  
  SELECT id, x from ... WHERE....  
  UNION ALL  
   SELECT id, x from ... WHERE...  
  )  
  
  WITH #table2  
  (  
   SELECT DISTINCT tbl_x.*,ROW_NUMBER() OVER (order by id) as RowNumber  
  WHERE id in ( SELECT id from #table1)  
  )  
  
  SELECT * FROM #table2 WHERE RowNumber &gt; ... and ...
  </code></pre>
  
  <p>So I have to use WITH on WITH and then SELECT on second WITH, How I can do that?</p>