title: Generating months between two dates?
body: <p>I want to fill in the missing months in a <code>SELECT</code> statement so I was planning on joining my table with another table that contains all months. How can I generate a table of months in a light-weight fashion?  For instance,</p>
  
  <pre><code>CREATE TABLE #TEMP(Timewhen DATETIME, Value INT)
  
  INSERT INTO #TEMP VALUES('2012-02-04', 4)
  INSERT INTO #TEMP VALUES('2012-02-06', 4)
  INSERT INTO #TEMP VALUES('2012-02-10', 4)
  INSERT INTO #TEMP VALUES('2012-04-08', 4)
  INSERT INTO #TEMP VALUES('2012-04-12', 4)
  
  SELECT YEAR(Timewhen) EventYear, MONTH(Timewhen) EventMonth, SUM(Value) Total
  FROM #TEMP
  GROUP BY YEAR(Timewhen), MONTH(Timewhen)
  
  DROP TABLE #TEMP
  </code></pre>
  
  <p>gives me:</p>
  
  <pre><code>EventYear   EventMonth  Total
  2012               2    12
  2012               4    8
  </code></pre>
  
  <p>But I need:</p>
  
  <pre><code>EventYear   EventMonth  Total
  2012        2           12
  2012        3           0
  2012        4           8
  </code></pre>