title: How to create Temp table with SELECT * INTO tempTable FROM CTE Query
body: <p>I have a MS SQL CTE query from which I want to create a temporary table. I am not sure how to do it as it gives an <code>Invalid Object name</code> error.</p>
  
  <p>Below is the whole query for reference</p>
  
  <pre><code>SELECT * INTO TEMPBLOCKEDDATES FROM 
  ;with Calendar as (
      select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime,EventEndTime, EventRecurring, EventStartDate as PlannedDate
      ,EventType from EventCalender
      where EventActive = 1 AND LanguageID =1 AND EventBlockDate = 1
      union all
      select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime,EventEndTime, EventRecurring, dateadd(dd, 1, PlannedDate)
      ,EventType from Calendar
      where EventRecurring = 1
          and dateadd(dd, 1, PlannedDate) &lt;= EventEndDate 
  )
  select EventID, EventStartDate, EventEndDate, PlannedDate as [EventDates], Cast(PlannedDate As datetime) AS DT, Cast(EventStartTime As time) AS ST,Cast(EventEndTime As time) AS ET, EventTitle
  ,EventType from Calendar
  where (PlannedDate &gt;= GETDATE()) AND ',' + EventEnumDays + ',' like '%,' + cast(datepart(dw, PlannedDate) as char(1)) + ',%'
      or EventEnumDays is null
  order by EventID, PlannedDate
  option (maxrecursion 0)
  </code></pre>
  
  <p>I would appreciate a point in the right direction or if I can create a temporary table from this CTE query </p>