Last active
April 2, 2020 08:51
-
-
Save annibuliful/0e55cc186ba03269bc995518f526bb0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- question 1 | |
CREATE PROCEDURE proc_customerOrder @date DATE, @orderCount INT | |
AS BEGIN | |
SELECT | |
Orders.OrderNum, | |
Orders.OrderDate, | |
Orders.CustomerNum, | |
COUNT(OrderLine.NumOrdered) AS AmountOrder, | |
SUM(OrderLine.QuotedPrice) AS SumPrice | |
FROM | |
Orders | |
INNER JOIN OrderLine ON OrderLine.OrderNum = Orders.OrderNum | |
GROUP BY Orders.OrderNum, Orders.OrderDate, Orders.CustomerNum | |
HAVING Orders.OrderDate = @date AND COUNT(OrderLine.NumOrdered) >= @orderCount | |
END; | |
-- question 2 | |
CREATE OR ALTER PROCEDURE proc_insertOrder @amount INT, @part NVARCHAR (10), @customerNum INT | |
AS | |
BEGIN | |
INSERT INTO Orders (OrderNum, OrderDate, CustomerNum) | |
VALUES( | |
(SELECT MAX(OrderNum) + 1 FROM Orders), | |
GETDATE (), | |
@customerNum); | |
INSERT INTO OrderLine (OrderNum, PartNum, QuotedPrice) | |
VALUES ( | |
(SELECT MAX(OrderNum) FROM Orders), | |
@part, | |
(SELECT Part.Price * @amount FROM Part WHERE Part.PartNum = @part) | |
); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment