Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Efficient paging using SQL script

, 10 Jan 2012
Rate this:
Please Sign up or sign in to vote.
string Query = string.Format(@"SELECT * FROM (SELECT *, " + @"ROW_NUMBER() OVER(ORDER BY PRODUCT_ID DESC ) AS ROW_NUM FROM({0}) " + @"AS TEMP_INNER) AS TEMP_OUTER WHERE ROW_NUM BETWEEN '{1}' AND " + @"({2} + {3}) - 1", strSql, startRowIndex, startRowIndex, maximumRows);
string Query = string.Format(@"SELECT * FROM (SELECT *, " + 
     @"ROW_NUMBER() OVER(ORDER BY PRODUCT_ID DESC ) AS ROW_NUM  FROM({0}) " + 
     @"AS TEMP_INNER) AS TEMP_OUTER  WHERE ROW_NUM BETWEEN '{1}' AND " + 
     @"({2} + {3}) - 1", strSql, startRowIndex, startRowIndex, maximumRows);

License

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

About the Author

kamiktk
Software Developer PowerObjects
Pakistan Pakistan
I am a professional Software Developer. I have experience in developing Windows Applications using C# and Java, e-commerce Portals, Content Management Systems and Data driven websites.
My technical forte includes: C/C++, Java, C#, ASP.NET, ADO.NET, JavaScript, jQuery, SQL Server, Design Patterns.
My interests involves programming, website development, developing applications for Android and learning subjects related to Software Engineering/Information Systems. Currently I am working as a Software Engineer at PowerObjects Pvt Ltd.

Comments and Discussions

 
GeneralI think that it comes down to the proper separation of the l... PinmemberRiverama26-Jan-12 12:39 
GeneralIgnoring the issues with not using SQL parameters, why not j... PinmemberAndrew Rissing10-Jan-12 4:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 10 Jan 2012
Article Copyright 2012 by kamiktk
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid