SQL stored procedure written with temp table

Source: Internet
Author: User
Tags id3

Create procR_productuse_m (@id1 int,@id2 int,@id3 int) asbegin---Temporary table 1SelectA.id1,b.id2,c.id3 into#linshi_1 fromTable_a asA,table_b asB,table_c asCwhereA.id1=@id2---Temporary table 2SelectC.ID3,sum(A.L2),Month(B.L3), B.L1 into#linshi_2 fromTable_a asA,table_b asB,table_c asCwhere[Email protected]Group  by Month(b.13)---ResultsSelect#linshi_1. Id1, #linshi_1. Id2 from#linshi_1 Left Join#linshi_2 on#linshi_1. id1=#linshi_2. Id2EndGo

A # is a local variable, such a temporary table can only be used in this stored procedure

Two # #为全局临时表, can be used outside the stored procedure, you need to manually delete the drop table # #表名

SQL stored procedure written with temp 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.