I do not use sqlserver
and for this reason I have set myself the task to consult how to create a limit
, I have realized that to bring a certain number of records from a query I use SELECT TOP cantidad
, execute the query and it effectively brought me the number of records...
The problem I have is how to tell the query to bring me from one initial value to another, that is, from 1000 to 2000.
JUDGMENT
SELECT TOP ".$rowperpage."
maepro.PRCODI,
maepro.PrNomb
FROM
maepro
WHERE
maepro.PrSta = 'S' ".$searchQuery." ORDER BY maepro.PrNomb ASC";
I would appreciate the interest.
It uses the
offset
and clausesfetch
, which are part of the clauseorder by
starting with SQL Server 2008.Its usage is like this:
offset
you indicate the row offset at which your current page starts.fetcn next X rows only
you indicate the size of the page.Which will look like this in a query:
Try adding the following to your query right after the ORDER BY
Offset is the Keyword to indicate how many records to skip and with the use of Fetch we indicate how many records to take
Here is the source you refer to
It is recommended that when executing the clause
Order By
, you take fields that are different. That is, first you execute:Later: