Kizspy.me
Question 8:
Picture 7.1
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.
Zoom
7 of 7
Paper No: 2
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 Medical Records
where RecordDate < '2022-01-01'
Diagnosis
Year NumberOfPatients
1
Allergy
2019 3
2
Allergy
2020 4
3
Allergy
2021 2
4
Arthritis
2019 3
Arthritio
20004
+ 95%
Close