title: How to create recursive query to get all dates between two dates
body: <p>I want to get all dates between two dates <code>arrival date</code> and <code>leaving date</code>.</p>
  
  <p>I tried that recursive query but it didn't work.</p>
  
  <pre><code>;with dates as ( 
  SELECT GuestID, ArrivalDate as reserveddate 
  from dbo.Guest 
  union all 
  SELECT GuestID, dateadd (day,1,dbo.Guest. ArrivalDate) as reserveddate 
  from dbo.Guest 
  where dateadd (day,1,dbo.Guest. ArrivalDate) &lt;dbo.Guest.leavingate
  ) 
  
  SELECT * 
  from dates 
  option (maxrecursion 0)
  </code></pre>