title: Msg 208, Level 16, State 1, Line 1 Invalid object name
body: <p>I'm trying to SELECT from <strong>SalesData</strong> that created using <strong>WITH</strong>,
  the query is </p>
  
  <pre><code>    with SalesData (TotalSold, OrderYear, TerritoryName)
      AS (
  
      SELECT SUM(soh.TotalDue) AS 'TotalSold'
          , YEAR(soh.OrderDate) AS 'OrderYear'
          , st.Name AS 'TerritoryName'
      FROM Sales.SalesOrderHeader AS soh
      INNER JOIN Sales.SalesTerritory AS st
      ON soh.TerritoryID = st.TerritoryID
      GROUP BY YEAR(soh.OrderDate)
              ,st.Name
  )
  SELECT TotalSold FROM SalesData
  </code></pre>
  
  <p>but SSMS gives me this error: </p>
  
  <blockquote>
    <p>Msg 208, Level 16, State 1, Line 1 Invalid object name</p>
  </blockquote>
  
  <p>I'm using Avdentureworks Database sample.</p>
  
  <p><img src="https://i.stack.imgur.com/Q4RWe.png" alt="enter image description here"></p>
  
  <p>any idea why is this happening? while it's been executed well in the demo video
  that I'm watching. </p>