forked from khushi-k-shah/AKAHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsp3.sql
More file actions
42 lines (33 loc) · 986 Bytes
/
Copy pathsp3.sql
File metadata and controls
42 lines (33 loc) · 986 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- function returns all patients in the portal between an input range for age, inclusive
-- commands to call in mysql:
-- cp procdure below into mysql, CALL patientsInRange(15, 20, @out_total); , SELECT @out_total
DROP PROCEDURE IF EXISTS patientsInRange;
DELIMITER //
CREATE PROCEDURE patientsInRange (IN beg_age int(11), IN end_age int(11), OUT list varchar(500))
BEGIN
DECLARE noMoreRow int default 0;
DECLARE name_id varchar(50);
DECLARE patient_age int(11);
DECLARE num INT;
DECLARE cur CURSOR FOR SELECT age, name FROM Basic_Patient_Info;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET noMoreRow = 1;
OPEN cur;
set list = "";
set num = 0;
getList:LOOP
FETCH cur INTO patient_age, name_id;
IF (noMoreRow = 1) THEN
LEAVE getList;
END IF;
IF patient_age >= beg_age AND patient_age <= end_age then
IF num = 0 then
set list = CONCAT(list, name_id);
ELSE
set list = CONCAT(list,", ", name_id);
END IF;
SET num = num + 1;
END IF;
END LOOP getList;
CLOSE cur;
END //
DELIMITER ;