Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I have a big web-site(ASP.NET) with a huge data-base(MS-SQL) and i searched for a good way to use paging in my web-site.
I found two good way's to do it but i have a little problem to decide which paging way to use,
The first way to is to use ROW_NUMBER() in this why:

With ListRec As(
SELECT ROW_NUMBER() OVER(ORDER BY field1,field2) AS rownum,field1,field2,field3 FROM [MyTable] WHERE MyCondition
)
SELECT *
FROM ListRec
WHERE rownum > 90 and rownum <= 100



The second way to is to use NOT IN in this why:

SELECT TOP 10 field1,field2,field3 FROM [MyTable]
WHERE (field1 NOT IN (SELECT TOP 90 field1 FROM [MyTable] WHERE MyCondition ORDER BY field1,field2)) And MyCondition ORDER BY field1,field2


So, Which way is the best way ?


Thanks,
Roy Shoa.
Posted

1 solution

First option is better to use


wrote:
With ListRec As(
SELECT ROW_NUMBER() OVER(ORDER BY field1,field2) AS rownum,field1,field2,field3 FROM [MyTable] WHERE MyCondition
)
SELECT *
FROM ListRec
WHERE rownum > 90 and rownum <= 100
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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