Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Efficient paging using SQL script

0.00/5 (No votes)
10 Jan 2012CPOL 8.4K  
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);
C#
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)