Common paging Storage
DECLARE @SQL NVARCHAR( -) SET @SQL = 'SELECT @TotalCount =count (1) from #temptable' + @Condition EXECsp_executesql@SQLN'@TotalCount INT OUTPUT',@TotalCountOUTPUTDECLARE @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)
Create a temporary table
IF object_id('tempdb: #tempMettings') is not NULL DROP TABLE#tempMettingsSELECTa.id, A.metting_datebet, A.meeting_dateend, A.metting_date, A.mettin G_time, A.meeting_ftime, A.site, A.sitetype into#tempMettings from(SELECTId, Metting_datebet, Meeting_dateend, Mett Ing_date, Meeting_fdate metting_time, Meeting_ftime, Site, SiteType frommobile_manager_mettingsWHERESiteType= '2' andStatus not inch(0,7,2)) a