title: Generating a Date Span from a Table with Monthly Entries
body: <p>Let's say we have a table that looks like this in SQL Server 2012:</p>
  
  <pre><code>YYYYMM | Mbr_ID | Product_ID
  ----------------------------
  201501 | 000001 | AA
  201502 | 000001 | AA
  201503 | 000001 | AB
  201504 | 000001 | AA
  201505 | 000001 | AA
  201506 | 000001 | AA
  </code></pre>
  
  <p>There will be multiple members, and they might switch products multiple times, but never within a given month.</p>
  
  <p>I am looking to turn this into a span table, something like the following:</p>
  
  <pre><code>CMonth_Start | CMonth_End | Mbr_ID | Product_ID
  -----------------------------------------------
  201501       | 201502     | 000001 | AA
  201503       | 201503     | 000001 | AB
  201504       | 201506     | 000001 | AA
  </code></pre>
  
  <p>If I try to do this using MIN(YYYYMM) and MAX(YYYYMM), I would only get the outer span (201501-201506) for the first product. I know there's got to be some way to do this, and I'm sure it's something simple, but I just can't think of it right now. I would really appreciate any help you all could give me, thanks for reading!</p>