Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a table which contains 1000 records I have to fetch 10 records every time but next !0 record on every execution. Can Any one help me?
Posted

If you would like to achieve something similar to pagination, please have a look at example:
SQL
DECLARE @tmp TABLE (ID INT IDENTITY(1,1), SomeText VARCHAR(10))

INSERT INTO @tmp (SomeText)
VALUES('A'),('B'),('C'),('D'),('E'),
        ('F'),('G'),('H'),('I'),('J'),
        ('K'),('L'),('M'),('N'),('O'),
        ('P'),('Q'),('R'),('S'),('T'),
        ('U'),('V'),('X'),('Y'),('Z')


DECLARE @counter INT=1

SELECT A.*
FROM (
    SELECT ROW_NUMBER() OVER(ORDER BY ID) AS RowNo, *
    FROM @tmp
    ) AS A
WHERE RowNo BETWEEN @counter*10-9 AND @counter *10

SET @counter =2

SELECT A.*
FROM (
    SELECT ROW_NUMBER() OVER(ORDER BY ID) AS RowNo, *
    FROM @tmp
    ) AS A
WHERE RowNo BETWEEN @counter*10-9 AND @counter *10


This is only an idea, but i hope this is what you're looking for.

As you can see, first query returns 10 records (1-10) and second one (11-20).
 
Share this answer
 
SQL
SELECT TOP 10 FROM Employee WHERE Name like '%abc%'

You stuck at here ?

-KR
 
Share this answer
 
Comments
Member 10310320 21-Feb-14 11:26am    
No I want to get 10 records just like pagination?
Krunal Rohit 21-Feb-14 11:27am    
What is the scenario ?

-KR

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