title: Transact-SQL - number rows until condition met
body: <p>I'm trying to generate the numbers in the &quot;x&quot; column considering the values in field &quot;eq&quot;, in a way that it should assign a number for every record until it meets the value &quot;1&quot;, and the next row should reset and start counting again. I've tried with <code>row_number</code>, but the problem is that I only have ones and zeros in the column I need to evaluate, and the cases I've seen using <code>row_number</code> were using growing values in a column. Also tried with rank, but I haven't managed to make it work.</p>
  <pre><code>nInd    Fecha       Tipo    @Inicio     @contador_I  @Final     @contador_F eq  x
  1       18/03/2002  I       18/03/2002  1            null       null        0   1
  2       20/07/2002  F       18/03/2002  1            20/07/2002 1           1   2
  3       19/08/2002  I       19/08/2002  2            20/07/2002 1           0   1
  4       21/12/2002  F       19/08/2002  2            21/12/2002 2           1   2
  5       17/03/2003  I       17/03/2003  3            21/12/2002 2           0   1
  6       01/04/2003  I       17/03/2003  4            21/12/2002 2           0   2
  7       07/04/2003  I       17/03/2003  5            21/12/2002 2           0   3
  8       02/06/2003  F       17/03/2003  5            02/06/2003 3           0   4
  9       31/07/2003  F       17/03/2003  5            31/07/2003 4           0   5
  10      31/08/2003  F       17/03/2003  5            31/08/2003 5           1   6
  11      01/09/2005  I       01/09/2005  6            31/08/2003 5           0   1
  12      05/09/2005  I       01/09/2005  7            31/08/2003 5           0   2
  13      31/12/2005  F       01/09/2005  7            31/12/2005 6           0   3
  14      14/01/2006  F       01/09/2005  7            14/01/2006 7           1   4
  </code></pre>