Next order stored Procedure-MYSQL

Source: Internet
Author: User

BEGIN    DECLARESmarkINT; DECLAREOrderIdINT; /*query whether a course exists and does not perform an order operation if it does not exist*/    SET @count =(SELECT Count(1) fromT_courseWHEREId=CourseID); IF @count = 0  Then         SELECT"Noexist"; ELSE         /*Check whether a course has been registered, if you have already signed up, you do not need to register*/        SET @c1 =(SELECT COUNT(1) fromT_shoporder SDWHERESd.user_id =Userid andsd.course_id=CourseID andSd.is_delete= 0);/*the course I enrolled*/        IF @c1 = 0  Then            /*If you do not register*/            /*setup of order number*/            SET @orderNum = CONVERT(CONCAT ("Ms_", Date_format (Now (),'%y%m%d'), CourseID, Ceil (RAND()* 99999), userId),CHARACTER); SET @price =(SELECTTprice fromT_courseWHEREId=CourseID); /*Save Order*/            INSERT  intoT_shoporder (user_id, Is_delete, num, price, description, IP,             IpAddress, Order_number, STATUS, course_id, type )VALUES(UserId,0, Tnum,@price, CONCAT ("User" ", username," ", in", Date_format (Now (),'%y-%m-%d'), "Located", IP, "/", ipAddress," Submit order, quantity is ", Tnum,", Amount is: ¥ ",@price), IP, ipAddress,@orderNum,                0, CourseID,NULL            ); /*Query the last ID of the current order*/            SET @orderId =(SELECTId fromT_shoporderWHEREOrder_number= @orderNum); /*stitching order number to ensure unique*/            SET @onumber = CONVERT(CONCAT (@orderNum,@orderId),CHARACTER); /*Modify Order Number*/            UPDATET_shoporderSETOrder_number= @onumber WHEREId= @orderId; /*return order and status*/            SELECTCONCAT (@orderId,"#",0); ELSE            SELECTTs.id, Ts.status intoOrderId, Smark fromT_shoporder TSWHERETs.is_delete= 0  andts.course_id=CourseID andTs.user_iduserId; IFSmark= 0  Then                SELECTCONCAT (OrderId, "#",0);/*already paid for*/            ELSE                 SELECTCONCAT (OrderId, "#",1);/*already paid for*/            END IF; END IF; END IF;END;

Next order stored Procedure-MYSQL

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.