Create a function named F2 which calculates and returns an integer number which is the number of distinct patients who were required to do a given test during their appointments,where testID int is the input parameter of the function.
For example, when we call the F2 function in the following query for calculating the number of distinct patients who were required to do each of the four tests with testID respectively 9,10, 11 and 12, the results must be shown as in the following figure:
select TestID, Name, dbo.F2(TestID) as NumberOfPatients
from Tests
where TestID in (9,10,11,12)
TestID
9
10
11
12
Name
NumberOfPatients
5
2
5
8
1
2
3
4
Thyroid Test
Liver Function Test
Kidney Function Test
Complete Blood Count
Picture 8.1
Question 9:
Create a trigger named insertDoctor for the INSERT statement on the "Doctors" table so that when we execute an insert statement to add one or more rows to the "Doctors" table, if any of the inserted rows have the DepartmentID as null, the system will automatically set the DepartmentID of those rows to the DepartmentID of the department named 'Cardiology'.
For example, if we execute the following statements to insert two doctors (one with DepartmentID=NULL and the other with DepartmentID=5) and then select these two doctors,we can see that the DepartmentID of the doctor with DepartmentID=null is set to the id of the department named 'Cardiology' as shown in the following figure:
Close
+ 100%
Zoom