Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you choose to (or need to) go with an ad-hoc table and not a permanent one, this would do it:</p> <pre><code>CREATE FUNCTION dbo.DateList ( @MinDate datetime ,@MaxDate datetime ) RETURNS TABLE RETURN WITH Pass0 as (select 1 as C union all select 1), --2 rows Pass1 as (select 1 as C from Pass0 as A, Pass0 as B),--4 rows Pass2 as (select 1 as C from Pass1 as A, Pass1 as B),--16 rows Pass3 as (select 1 as C from Pass2 as A, Pass2 as B),--256 rows Pass4 as (select 1 as C from Pass3 as A, Pass3 as B),--65536 rows Tally as (select row_number() over(order by C) as Number from Pass4) select dateadd(dd, Number - 1, @MinDate) DateValue from Tally where Number &lt; datediff(dd, @MindAte, @MaxDate) + 2 </code></pre> <p>GO</p> <p>And a testing call:</p> <pre><code>DECLARE @MinDate datetime ,@MaxDate datetime SET @MinDate = 'Jan 1, 2009' SET @MaxDate = 'Dec 31, 2009' SELECT * from dbo.DateList(@MinDate, @MaxDate) </code></pre> <p>Wierd--this is the third SO post today that involved Tally tables. Must be some odd sunspot activity going on. Here are the linkes:</p> <p><a href="https://stackoverflow.com/questions/1394153/count-number-of-rows-that-occur-for-each-date-in-column-date-range/1394182">count number of rows that occur for each date in column date range.</a><br> <a href="https://stackoverflow.com/questions/1393951/what-is-the-best-way-to-create-and-populate-a-numbers-table/1394239" title="What is the best way to create and populate a numbers table?">What is the best way to create and populate a numbers table?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload