title: SQL - how to select only those rows up to a certain row by rownumber
body: <p>I'm having difficulty constructing a SQL query for loading a file into a database.</p>
  <p>Let's say my file looks like this:</p>
  <pre><code>col1  col2        col3 col4
  a     b           c    d
  e     f           g    h
  end   null        null null
  no    interesting data here
  not   interested  in   this
  bla   bla         bla  bla
  </code></pre>
  <p>I want to select ONLY the rows up to the 'end' row. So:</p>
  <pre><code>col1  col2        col3 col4
  a     b           c    d
  e     f           g    h
  </code></pre>
  <p>The end-row and thereafter are not interesting for my application. The end row is at a different row number for each file we need to load. So I can't use a counter or a TOP statement for this.</p>
  <p>How would I go about this?</p>
  <p>I suspect I'd need to take care of this in the WHERE clause as follows:</p>
  <pre><code>SELECT *
  FROM data
  WHERE rownumber &lt; endrownumber
  </code></pre>
  <p>Where I'm stuck is the following:</p>
  <ol>
  <li>how to find the rownumber where col1 = 'end' (as the endrownumber)</li>
  <li>how to <em>only</em> select those rows where the rownumber &lt; endrownumber</li>
  <li>Is this possible to achieve with a sub-query within the where clause?</li>
  </ol>
  <p>Thanks!</p>
  <p>T</p>