title: How can I generate a temporary table filled with dates in SQL Server 2000?
body: <p>I need to make a temporary table that holds of range of dates, as well as a couple of columns that hold placeholder values (0) for future use.  The dates I need are the first day of each month between $startDate and $endDate where these variables can be several years apart.</p>
  
  <p>My original sql statement looked like this:</p>
  
  <pre><code>select dbo.FirstOfMonth(InsertDate) as Month, 0 as Trials, 0 as Sales
  into #dates
  from customer
  group by dbo.FirstOfMonth(InsertDate)
  </code></pre>
  
  <p>"FirstOfMonth" is a user-defined function I made that pretty much does what it says, returning the first day of the month for the provided date with the time at exactly midnight.</p>
  
  <p>This produced almost exactly what I needed until I discovered there were occasionally gaps in my dates where I had a few months were there were no records insert dates.  Since my result must still have the missing months I need a different approach.</p>
  
  <p>I have added the following declarations to the stored procedure anticipating their need for the range of the dates I need ...</p>
  
  <pre><code>declare $startDate set $startDate = select min(InsertDate) from customer
  declare $endDate set $endDate = select max(InsertDate) from customer
  </code></pre>
  
  <p>... but I have no idea what to do from here.</p>
  
  <p>I know this question is <a href="https://stackoverflow.com/questions/2160188/how-can-i-get-a-table-of-dates-from-the-first-day-of-the-month-two-months-ago-t">similar to this question</a> but, quite frankly, that answer is over my head (I don't often work with SQL and when I do it tends to be on older versions of SQL Server) and there are a few minor differences that are throwing me off.</p>