title: Selecting every nth row from SQL Server 2008 query result where table does not have row id column
body: <p>I feel so close... I think my problem is how I'm using the MOD function combined with the <code>ROW_NUMBER()</code> function, but I don't understand what I'm doing wrong.   </p>
  
  <p>I'm using the <code>ROW_NUMBER()</code> function because I need a way to select every "nth" row. I've read the other pages about this (I used them to create my SQL)...but I'm getting an error from SQL Server. I need the inner table join (2 instances of the table <code>Tick_OneMin</code>, <code>H1</code> and <code>H2</code>) to get prices of different securities at the same time snapshot.  </p>
  
  <p>If I comment out the line with the <code>MOD</code> function...the SQL executes fine...but if I put it in....SQL Server throws the error message:</p>
  
  <blockquote>
    <p><em>An expression of non-boolean type specified in a context where a condition is expected, near 'MOD'.</em></p>
  </blockquote>
  
  <p>Here is my attempt at the SQL--</p>
  
  <pre><code>SELECT 
     ROW_NUMBER() OVER (ORDER BY H1.CombDateTime ASC) AS RowID,
     H1.CombDateTime, 
     H1.Close_PX as 'TYA_Close', 
     H2.Close_PX 'ESA_Close'
  FROM 
     Tick_OneMin as H1, Tick_OneMin as H2
  WHERE 
     H1.Ticker = 'TYA'
     AND H2.Ticker = 'ESA'
     AND H1.CombDateTime &gt;= '12/28/2012 10:00 AM'
     AND H1.CombDateTime &lt;= '12/28/2012 10:30 AM'
     AND H1.CombDateTime = H2.CombDateTime
     AND RowID MOD 4 = 0     
     -- this "RowID MOD 4 = 0" is throwing an error in SQL Server
  ORDER BY 
     H1.CombDateTime ASC
  </code></pre>
  
  <p>My table looks like the following (1 table with 3 columns)</p>
  
  <p>Table <code>Tick_OneMin</code></p>
  
  <pre><code>Ticker - CombDateTime - Close_PX
  ------------------------------------
  ES     - 1/3/2012 10:00 AM    - 1470
  ZN     - 1/3/2012 10:00 AM   - 132.5
  ES     - 1/3/2012 10:01 AM   - 1475
  ZN     - 1/3/2012 10:01 AM   - 133
  </code></pre>
  
  <p>and I want to create the following output</p>
  
  <pre><code>Date  -   ZN.Price -  ES.Price
  ====     ========   ========
  1/3/2012 -  132.5  - 1470
  1/3/2012 -  133    - 1475
  </code></pre>
  
  <p>Any ideas why SQL SErver is throwing the error?</p>