首页 > 数据库技术 > 详细

SQL临时表加分页操作

时间:2014-07-23 12:34:16      阅读:632      评论:0      收藏:0      [点我收藏+]

常用的分页存储

    DECLARE @SQL NVARCHAR(2000)
    SET @SQL = SELECT @TotalCount=COUNT(1) FROM #temptable + @Condition
    EXEC sp_executesql @SQL, N@TotalCount INT OUTPUT, @TotalCount OUTPUT 
    DECLARE @ExeSQL NVARCHAR(4000)  
    SET @ExeSQL =    WITH temp
              AS ( SELECT TOP  + @LastRow
        + 
                            #temptable.* ,
                            ROW_NUMBER() OVER ( ORDER BY #temptable.MeetID ) AS PX
                   FROM     #temptable  + @Condition + 
                   ORDER BY #temptable.MeetID
                 )
        SELECT  *
        FROM    temp
        WHERE   PX >= + @FirstRow 

    EXEC (@ExeSQL)    

创建临时表

IF OBJECT_ID(tempdb..#tempMettings) IS NOT NULL 
        DROP TABLE    #tempMettings

    SELECT  a.Id ,
            a.Metting_DateBet ,
            a.Meeting_DateEnd ,
            a.Metting_Date ,
            a.Metting_Time ,
            a.Meeting_FTime ,
            a.Site ,
            a.SiteType
    INTO    #tempMettings
    FROM    ( SELECT    Id ,
                        Metting_DateBet ,
                        Meeting_DateEnd ,
                        Metting_Date ,
                        Meeting_FDate Metting_Time ,
                        Meeting_FTime ,
                        Site ,
                        SiteType
              FROM      Mobile_Manager_Mettings
              WHERE     SiteType = 2
                        AND Status NOT IN ( 0, 7, 2 )
            ) a

SQL临时表加分页操作,布布扣,bubuko.com

SQL临时表加分页操作

原文:http://www.cnblogs.com/WolfBlog/p/3862488.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!