title: how to find row number of first non zero value in a column in SQL Server 2012
body: <p>I have a table <code>T1</code> with columns <code>countryid, stateid, Value</code>.</p>
  
  <p>I need row number of <code>stateid</code> value which has the first non-zero value for every country. Data in the table is ordered by <code>CountryId ASC, StateId ASC</code>.</p>
  
  <pre><code>(Countryid, Stateid, Value)
  (1, 11, 0)
  (1, 12, 1)
  (1, 13, 0)
  (2, 21, 0)
  (2, 22, 0)
  (2, 23, 1)
  (3, 31, 0)
  (3, 32, 10)
  (3, 33, 0)
  (3, 34, 20)
  </code></pre>
  
  <p>I need output like below.</p>
  
  <ul>
  <li>for countryid 1, row number I need as output should be 2.</li>
  <li>for countryid 2, row number I need as output should be 3.</li>
  <li>for countryid 3, row number I need as output should be 2.</li>
  </ul>