Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In SQL Server 2012, there is support for the ANSI standard <code>OFFSET</code> / <code>FETCH</code> syntax. I <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/10/sql-server-11-denali-using-the-offset-clause.aspx">blogged about this</a> and here is <a href="http://msdn.microsoft.com/en-us/library/ms188385%28v=sql.110%29.aspx">the official doc</a> (this is an extension to <code>ORDER BY</code>). Your syntax converted for SQL Server 2012 would be:</p> <pre><code>SELECT ID, Name, Price, Image FROM Products ORDER BY ID ASC OFFSET (@start_from - 1) ROWS -- not sure if you need -1 -- because I don't know how you calculated @start_from FETCH NEXT @items_on_page ROWS ONLY; </code></pre> <p>Prior to that, you need to use various workarounds, including the <code>ROW_NUMBER()</code> method. See <a href="http://www.sqlservercentral.com/articles/T-SQL/66030/">this article</a> and the <a href="http://www.sqlservercentral.com/Forums/Topic672980-329-1.aspx">follow-on discussion</a>. If you are not on SQL Server 2012, you can't use standard syntax or MySQL's non-standard <code>LIMIT</code> but you can use a more verbose solution such as:</p> <pre><code>;WITH o AS ( SELECT TOP ((@start_from - 1) + @items_on_page) -- again, not sure if you need -1 because I -- don't know how you calculated @start_from RowNum = ROW_NUMBER() OVER (ORDER BY ID ASC) /* , other columns */ FROM Products ) SELECT RowNum /* , other columns */ FROM o WHERE RowNum &gt;= @start_from ORDER BY RowNum; </code></pre> <p>There are many other ways to skin this cat, this is unlikely to be the most efficient but syntax-wise is probably simplest. I suggest reviewing the links I posted as well as the duplicate suggestions noted in the comments to the question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload