1 CREATE PROCEDURE [dbo]. [Proc_px_practice]2@PageSizeint, --number of pages per page3@CurrPageint--Current Page4 5 as6 begin7 CREATE TABLE #temp_table (8row_idintIdentity1,1) Primary Key notNULL, --row_id self-growth9Itemguid varchar ( -), --GuidTenPlanguid varchar ( -), OneName varchar ( -), --name AItemTypeint--type - - ) the - ---Plan - INSERT INTO #temp_table (itemguid,planguid,name,itemtype) + ( - SelectRowguid,rowguid,planname,'0' fromPx_plan + ) A at--Courses - INSERT INTO #temp_table (itemguid,planguid,name,itemtype) - ( - SelectCourseguid,planguid,coursename,'1' fromPx_plancoursewhere -Planguidinch(SelectPlanguid from#temp_tablewhereItemtype='0') - in ) - to--Courseware + INSERT INTO #temp_table (itemguid,planguid,name,itemtype) - ( the SelectA.rowguid,b.planguid,a.name,'2' fromPx_courseware A, #temp_table bwhere *A.courseguid=b.itemguid and B.itemtype='1' $ )Panax Notoginseng - the--Output + declare @StrSql varchar (max) ADECLARE @TopIndexint the Set@TopIndex = (@CurrPage-1)*@Pagesize + Set@StrSql ='Select Top'+str (@Pagesize) +'* from #temp_table where itemguid isn't in (select top'+str (@TopIndex) +'Itemguid from #temp_table Order by row_id) Order by row_id' - $ exec (@StrSql) $ - - Select* from#temp_table ORDER BY ItemType the - EndWuyi the - Wu - About $ -GO
View Code
Create a temporary table in the stored procedure and insert the data directly into the table