title: 'Invalid object name' error for Common Table Expression (CTE) even though CTE has been defined
body: <p>I am using SQL server 2012. I have three CTEs defined in a row as shown below:</p>
  
  <pre><code>;WITH X_CTE (A, B, C, D)
  AS (
      ...
  )
  ,
  Y_CTE (A, B, C, D)
  AS (
      ...
  )
  ,
  Z_CTE (A, B, C, D)
  AS (
      ...
  )
  </code></pre>
  
  <p>Then, I insert these CTEs into a table, whose schema is defined and matches that of the CTEs</p>
  
  <pre><code>INSERT INTO MyTable SELECT * FROM X_CTE
  INSERT INTO MyTable SELECT * FROM Y_CTE
  INSERT INTO MyTable SELECT * FROM Z_CTE
  </code></pre>
  
  <p>I am getting a 'Invalid object name' error for the CTEs in the three <code>INSERT INTO</code> statements. In fact, I get the same errors with <code>SELECT</code> statements:</p>
  
  <pre><code>SELECT * FROM X_CTE
  SELECT * FROM Y_CTE
  SELECT * FROM Z_CTE
  </code></pre>
  
  <p>Would you please point out what is wrong here?</p>
  
  <p>Thanks</p>
  
  <p>-Rohan.</p>