Create a temporary table in the stored procedure and insert the data directly into the table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.