7 of 7
Paper No: 8
Create a function named F1 which calculates and returns an integer number which is the number of distinct patients having appointments with doctors of a given department, where departmentID int is the input parameter of the function.
For example, when we call the F1 function in the following query for calculating the number of distinct patients having appointments with the two departments 'Cardiology' and 'Pediatrics', the results must be shown as in the following figure:
select DepartmentID, Name, dbo. F1 (DepartmentID) as NumberOfPatients
from Departments
where Departments. Name in ('Cardiology', 'Pediatrics')
DepartmentID
1
3
Name
NumberOfPatients
Cardiology
37
Pediatrics
32
1
2
Zoom
Dicture01
+ 100%
Close