title: Use multiple WITH tablename AS (...) statements SQL Server
body: <p>I'm trying to create two temporary tables and join them with a permanent table.  For example: </p>
  
  <pre><code>WITH temp1 AS (COUNT(*) AS count_sales, ID FROM table1 GROUP BY ID)
  WITH temp2 AS (COUNT(*) AS count_somethingelse, ID FROM table2 GROUP BY ID)
  SELECT *
  FROM table3 JOIN table2 JOIN table1
       ON table1.ID = table2.ID = table3.ID
  </code></pre>
  
  <p>but there seems to be an issue having multiple WITH tablename AS (...) statments.  I tried a semicolon.  </p>