-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateBills.sql
More file actions
27 lines (20 loc) · 776 Bytes
/
createBills.sql
File metadata and controls
27 lines (20 loc) · 776 Bytes
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
DROP PROCEDURE IF EXISTS createBills;
SET @rentSingleRoom = 2700;
SET @rentDoubleRoom = 4500;
SET @Internet = 50;
DELIMITER ;;
CREATE PROCEDURE createBills(IN thisResID varchar(5), IN thisBillDate varchar(6))
BEGIN
DECLARE doubleroom bool;
DECLARE thisBillID CHAR(32);
# generates random BillID, these can be the same:/ (Bressel doesn't care)
SET thisBillID = SUBSTR(MD5(rand()), 1, 16);
SET doubleroom = (SELECT DoubleRoom FROM Rooms NATURAL JOIN Lives WHERE ResID = thisResID);
IF doubleroom THEN
INSERT INTO Bills
VALUES (thisBillID, thisResID, thisBillDate, rentDoubleRoom, Internet, NULL, NULL);
ELSE
INSERT INTO Bills
VALUES (thisBillID, thisResID, thisBillDate, rentSingleRoom, Internet, NULL, NULL);
END;
;;