title: Get a list of dates between two dates using a function
body: <p>My question is similar to <a href="https://stackoverflow.com/questions/510012/get-a-list-of-dates-between-two-dates">this</a> MySQL question, but intended for SQL Server:</p>
  
  <p>Is there a function or a query that will return a list of days between two dates? For example, lets say there is a function called ExplodeDates:</p>
  
  <pre><code>SELECT ExplodeDates('2010-01-01', '2010-01-13');
  </code></pre>
  
  <p>This would return a single column table with the values:</p>
  
  <pre class="lang-none prettyprint-override"><code>2010-01-01
  2010-01-02
  2010-01-03
  2010-01-04
  2010-01-05
  2010-01-06
  2010-01-07
  2010-01-08
  2010-01-09
  2010-01-10
  2010-01-11
  2010-01-12
  2010-01-13
  </code></pre>
  
  <p>I'm thinking that a calendar/numbers table might be able to help me here.</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I decided to have a look at the three code answers provided, and the results of the execution - as a % of the total batch - are:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/1378788/1378788">Rob Farley's answer</a> : 18%</li>
  <li><a href="https://stackoverflow.com/a/1378866/1378866">StingyJack's answer</a> : 41%</li>
  <li><a href="https://stackoverflow.com/a/1378712/1378712">KM's answer</a> : 41%</li>
  </ul>
  
  <p><em>Lower is better</em></p>
  
  <p>I have accepted Rob Farley's answer, as it was the fastest, even though numbers table  solutions (used by both KM and StingyJack in their answers) are something of a favourite of mine. Rob Farley's was two-thirds faster.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>Alivia's <a href="https://stackoverflow.com/a/9207952/31532">answer</a> is much more succinct. I have changed the accepted answer.</p>