title: SQL Server - Counting number of times an attribute in a dataset changes (non-concurrently)
body: <p>I have a query that returns either a 1 or 0 based on whether or not an event occurred on a given date. This is ordered by date. Basically, a simple result set is:</p>
  
  <pre><code>Date         |  Type
  ---------------------
  2010-09-27      1
  2010-10-11      1
  2010-11-29      0
  2010-12-06      0
  2010-12-13      1
  2010-12-15      0
  2010-12-17      0
  2011-01-03      1
  2011-01-04      0
  </code></pre>
  
  <p>What I would now like to be able to do is to count the number of separate, non-concurrent instances of '0's there are - i.e. count how many different groups of 0s appear. </p>
  
  <p>In the above instance, the answer should be 3 (1 group of 2, then another group of 2, then finally 1 to end with).</p>
  
  <p>Hopefully, the above example illustrates what I am trying to get at. I have been searching for a while, but am finding it difficult to succinctly describe what I am looking for, and hence haven't found anything of relevance.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Josh</p>