首页 > 代码库 > SQL临时表加分页操作
SQL临时表加分页操作
常用的分页存储
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。