Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to select next 100 records in a query, what should i use,

like i have query
Select RegNo, PatientName, FCNo, RelationName, G.Description Gender, DATEDIFF(YYYY,DOB,GETDATE())'Age', R.Deleted from PRS.dbo.tblRegistration R LEFT OUTER JOIN TKC.dbo.tblGender G ON R.GenderID=G.GenderID

now how i get next 100 records every time.
Posted

One option is to do the following:

SQL
DECLARE @PageSize INT
DECLARE @Page INT
SELECT  @PageSize = 100,@Page = 2

;WITH temp_table  AS(
Select RegNo, PatientName, FCNo, RelationName, G.Description Gender, DATEDIFF(YYYY,DOB,GETDATE())'Age', R.Deleted, ROW_NUMBER() OVER(ORDER BY RegNo) ID  from PRS.dbo.tblRegistration R LEFT OUTER JOIN TKC.dbo.tblGender G ON R.GenderID=G.GenderID
)
SELECT  * FROM temp_table WHERE ID BETWEEN ((@Page - 1) * @PageSize + 1)  AND (@Page * @PageSize)


This can be in an SP, to which you can pass pagesize and page as parameters..
 
Share this answer
 
This is the simple way for getting next records from db..

SQL
-- you need to pass the @PAGENO for geting that part record
-- OR @RECORDNO is the variable which use for geting that much record..
-- here you need 100 record so, it will be seted to 100
-- you can use it as your way


DECLARE @PAGENO INT
DECLARE @RECORDNO INT
SET @PAGENO = 0
SET @RECORDNO = 100

SELECT TOP(@RECORDNO) * FROM OrderMaster
WHERE OrderMaster.OrderID NOT IN (
SELECT TOP (@PAGENO * @RECORDNO) OrderMaster.OrderID FROM OrderMaster)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900