title: SQL Server 2008 Emulating the LIMIT Function
body: <p>I've got the following  working query:</p>
  
  <pre><code>        string sqlString =
              "SELECT  * " +
              "FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id DESC) AS RowNum, * " +
              "FROM StreamView " +
              "WHERE Recipient = @Recipient " +
              ") AS RowConstrainedResult " +
              "WHERE RowNum &gt;= @startAt " +
              "AND RowNum &lt; @howMany " +
              "ORDER BY RowNum;";
  </code></pre>
  
  <p>Which then returns the proper rows given a startAt and howMany variables.
  I would like to do the same with the query below:</p>
  
  <pre><code>        string sqlString =
          "SELECT DISTINCT l.* FROM Streams l " +
          "INNER JOIN Friendships f ON f.Sender = @UserName OR f.Recipient = @UserName " +
          "WHERE l.Sender &lt;&gt; @UserName AND l.Recipient &lt;&gt; @UserName AND ( " +
          "l.Sender = f.Recipient OR l.Sender = f.Sender OR " +
          "l.Recipient = f.Sender OR l.Recipient = f.Recipient) " +
          "ORDER BY DateTime DESC;";
  </code></pre>
  
  <p>The query above works perfectly, but i'd like to get ranges instead of all the available rows. I need the same functionality of the first query.</p>
  
  <p>Ideas? thanks.</p>