Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.82 KB | None | 0 0
  1. DELIMITER //
  2.  
  3. CREATE PROCEDURE mockupNewOrder()
  4. BEGIN
  5.    insert into order_details
  6.    select
  7.     -- order id
  8.     odp.ProductID
  9.     ,p.UnitPrice
  10.     ,1 as `Quantity`
  11.     ,0 as `Discount`
  12.     from order_data_processing odp
  13.     left join product p on odp.ProductID = p.ProductID;
  14.    
  15.    
  16.     insert into orders
  17.     select
  18.     -- autoincrement OrderID,
  19.     odp.CustomerID,
  20.     1 as EmployeeID,
  21.     curdate() as OrderDate,
  22.     NULL as RequiredDate,  
  23.     NULL as ShippedDate,
  24.     1 as ShipVia,
  25.     1 as Freight,
  26.     c.CompanyName as ShipName,
  27.     c.Address as ShipAddress,
  28.     c.City as ShipCity,
  29.     c.Region as ShipRegion,
  30.     NULL as ShipPostalCode
  31.     from order_data_processing odp
  32.     left join customers c on odp.CustomerID = c.CustomerID;
  33.    
  34.     delete
  35.     from order_data_processing;
  36. END //
  37.  
  38. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement