A simple example of a stored procedure

Source: Internet
Author: User

1 delimiter $$2 CREATE PROCEDURE' Proc_ranking ' (inchSkuVARCHAR( -),inchSKUNameVARCHAR( -),inchStatusVARCHAR( -),inchSalesVARCHAR( -),inchTodayVARCHAR( -),inchOld_timeVARCHAR( -))3 BEGIN4     SET @sku =SKU;5     SET @skuname =SKUName;6     SET @status =status;7     SET @sales =sales;8     SET @today =today;9     SET @old_time =Old_time;Ten     SET @sql_header ="SELECT OneC. ' SKU ', c. ' Amt ', c. ' AVGs 'avg, S. ' SKUName ', S. ' Skupic ', S. ' EditTime ', St. ' Statusname ' A          from( -             SELECT -' SKU ',ROUND(SUM(' Amt '),2)'Amt',ROUND(SUM( `avg` )/7,2)'AVGs' the              from' Skusales ' -             WHERE     -' SKU '<> "' -              and' Paytime '> @old_time +              and' Paytime '< @today -             GROUP  by' SKU ') C +                Left JOIN A' Skustatus ' s onC. ' SKU '=S. ' SKU ' at                Left JOIN -' Statustype ' st onS. ' Sale_status '=St. ' PID ' -         WHERE -             1"; -     IF @sku <> "'  Then -     SET @sql_header =CONCAT (@sql_header," andC. ' SKU '= @sku"); in     END IF; -  to     IF @status <> "'  Then +     SET @sql_header =CONCAT (@sql_header," andS. ' Sale_status '= @status"); -     END IF; the  *     IF @skuname <> "'  Then $     SET @sql_header =CONCAT (@sql_header," andS. ' SKUName ' like @skuname");Panax Notoginseng     END IF; -  the     IF @sales <> "'  Then +     SET @sql_header =CONCAT (@sql_header," andC.avgs "); A     SET @sql_header =CONCAT (@sql_header,@sales); the     END IF; +     SET @sql_header =CONCAT (@sql_header,"ORDER  byC.amtDESC"); -  $     SET @sql_bodys = @sql_header; $      -     PREPAREstmt from @sql_bodys; -     EXECUTEstmt; the     deallocate PREPAREstmt; -         Wuyi     END$$

A simple example of a stored procedure

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.