페이지 별 sql

        ,      :   ,  <span id="transmark"></span>

          ,[ID] int IDENTITY (1,1)
  1.     :(  Not In SELECT TOP  )
    :  
SELECT TOP 10 *
FROM TestTable
WHERE (ID NOT IN
          (SELECT TOP 20 id
         FROM TestTable
         ORDER BY id))
ORDER BY ID


SELECT TOP     *
FROM TestTable
WHERE (ID NOT IN
          (SELECT TOP    *   id
         FROM  
         ORDER BY id))
ORDER BY ID
   2.     :(  ID     SELECT TOP  )
    :  
SELECT TOP 10 *
FROM TestTable
WHERE (ID >
          (SELECT MAX(id)
         FROM (SELECT TOP 20 id
                 FROM TestTable
                 ORDER BY id) AS T))
ORDER BY ID


SELECT TOP     *
FROM TestTable
WHERE (ID >
          (SELECT MAX(id)
         FROM (SELECT TOP    *   id
                 FROM  
                 ORDER BY id) AS T))
ORDER BY ID
  3.     :(  SQL         )

create  procedure SqlPager
@sqlstr nvarchar(4000), --     
@currentpage int, -- N 
@pagesize int --    
as
set nocount on
declare @P1 int, --P1    id
 @rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1, @rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as    --,@rowcount as    ,@currentpage as    
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off

     :      ,      ,        ,      。
       ,       ,       。

  SQL      ,    :     :
     :(  ID     SELECT TOP  )    ,    SQL  
     :(  Not In SELECT TOP  )       ,    SQL  
     :(  SQL         )        ,      

또 다른 하 나 는 줄 번호 가 내장 되 어 있 습 니 다.
 string SqlFormat, SqlAll, SqlBind;

            SqlFormat = "select * from ({0}) a where a.rownum between ({1}-1)*{2}+1 and {1}*{2}";

            SqlAll = "SELECT (ROW_NUMBER() OVER(ORDER BY " + StrOrder + ")) AS ROWNUM, A.* FROM ( " + StrSql + ") A";

            SqlBind = string.Format(SqlFormat, SqlAll, CurrentPage, PageSize);

            DataTable dt = dbop.GetDataSet(SqlBind).Tables[0];
           

좋은 웹페이지 즐겨찾기