별난 방법 : Paging by MS-SQLServer (Not In을 사용하지 않음)

User-Specific Records

To provide paging through user-specific data, you can use SELECT TOP with nested queries. The main advantages of this approach is that it does not require a unique key column of any sort and it also supports advanced navigation, where the user is able to move to the next, previous, first, and last pages, and is also able to move to a specific page.

The following pseudocode illustrates this technique.

SELECT TOP CustomerID,CompanyName,ContactName,ContactTitle
FROM
(SELECT TOP
CustomerID,CompanyName,ContactName,ContactTitle
FROM
Customers AS T1 ORDER BY ContactName DESC)
AS T2 ORDER BY ContactName ASC

The inner SELECT statement selects a set of rows in descending order based (in this example) on the ContactName column. The number of rows selected is equal to the current page number times the page size. The outer SELECT statement then selects the top n rows, where n is the page size, and presents the data in ascending order based on the ContactName column.

The following code shows the above pseudocode implemented as a stored procedure that can be used to page through the Customers table in the Northwind database.

출처 : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto05.asp

by 혼수상태 | 2007/08/16 08:26 | 트랙백

트랙백 주소 : http://isma44.egloos.com/tb/3694084
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
※ 로그인 사용자만 덧글을 남길 수 있습니다.

◀ 이전 페이지 다음 페이지 ▶