☑ Kizspy. me Question 8:
Create a function named F1 which calculates and returns an integer number which is the
number of distinct patients who have been diagnosed a given diagnosis in a given year
(based on the RecordDate), where Diagnosis nvarchar(255) and year int are respectively the
first and the second input parameters of the function.
For example, when we call the F1 function in the following query, the results must be shown
as in the following figure:
select distinct Diagnosis, YEAR(RecordDate) as Year, dbo.F1(Diagnosis,
YEAR(RecordDate)) as NumberOfPatients
from MedicalRecords
where RecordDate < '2022-01-01'
7 of 7
Paper No: 12
12
Zoom
+100%
Diagnosis
Allergy
Allergy
Year NumberOfPatients
2019 3
2020 4
Close