forked from ADB-course/20240819-20241125-adb-bbit2-2-classroom-semester-project-BBT3104-SemesterProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sql
More file actions
51 lines (41 loc) · 1.37 KB
/
script.sql
File metadata and controls
51 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DELIMITER $$
CREATE PROCEDURE `GetSalesOrderSummary`(IN StartDate DATE, IN EndDate DATE, OUT TotalAmount DOUBLE)
BEGIN
DECLARE totalSales DOUBLE DEFAULT 0.00;
DECLARE currentStatus VARCHAR(50);
DECLARE done INT DEFAULT 0;
-- Declare a cursor to iterate through statuses and calculate total sales
DECLARE salesCursor CURSOR FOR
SELECT
Status, SUM(Amount) AS TotalAmount
FROM
SalesOrder
WHERE
OrderDate BETWEEN StartDate AND EndDate
GROUP BY
Status;
-- Declare a handler for the cursor completion
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-- Initialize total sales
SET TotalAmount = 0.00;
-- Open the cursor
OPEN salesCursor;
read_loop: LOOP
FETCH salesCursor INTO currentStatus, totalSales;
IF done THEN
LEAVE read_loop;
END IF;
-- Add each status's total sales to the output
SET TotalAmount = TotalAmount + totalSales;
END LOOP;
-- Close the cursor
CLOSE salesCursor;
END $$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE `GetProductionReport`( IN StartDate DATE, IN EndDate DATE )
BEGIN SELECT BatchID, StartDate, EndDate, Volume,
Status FROM ProductionBatch WHERE StartDate
BETWEEN StartDate AND EndDate OR EndDate BETWEEN StartDate AND EndDate;
END $$
DELIMITER ;