title: How to get count of CTE result?
body: <p>I am new to sql, I have created a CTE now I want to get the count of rows from CTE result set</p>
  
  <pre><code>DECLARE @start_date date,@end_date DATE ;
  
  select @start_date= min(ETA) from  [dbo].[testTable]
          select @end_date=max(ETA) from  [dbo].[testTable];
  
      ;WITH  AllDays
                AS ( 
                SELECT   @start_date AS [Date]
                --, 1 AS [level]
                     UNION ALL
                     SELECT   DATEADD(DAY, 1, [Date])
                     --, [level] + 1
                     FROM     AllDays
                     WHERE    [Date] &lt; @end_date )
                     --Insert into #tempETA (CallETA) 
           SELECT [Date]--, [level]
           FROM   AllDays  OPTION (MAXRECURSION 0)
  
           select count(a.Date),a.Date from AllDays a 
  </code></pre>
  
  <p>I am getting error here: </p>
  
  <pre><code>(1048 row(s) affected)
  Msg 208, Level 16, State 1, Line 20
  Invalid object name 'AllDays'.
  </code></pre>