Need guidance on how to make EmailId
a child array of EventId
with JSON Path Expressions using the following schema:
Asked
Active
Viewed 49 times
-1
-
please include details from you fiddle in the question, you can't rely on SQL fiddle always being available. – Tanner Oct 05 '17 at 08:07
1 Answers
0
You can use this.
DECLARE @PatientId INT = 1
SELECT Event.*, RE.EmailId
FROM ( SELECT DISTINCT
E.EventId,
E.StartDate,
E.EndDate,
E.IsRecurring,
MRP.RecurringPatternId,
MRP.MedicationId,
PMR.PatientId
FROM
Event E
INNER JOIN MedicationRecurringPattern MRP ON E.EventId = MRP.EventId
INNER JOIN PatientMedicationReminders PMR ON E.EventId = PMR.EventId
WHERE
PMR.PatientId = @PatientId
) Event
LEFT JOIN ReminderEmails RE ON Event.EventId = RE.EVentId
LEFT JOIN Email ON RE.EmailId = Email.EmailId
FOR JSON AUTO

Serkan Arslan
- 13,158
- 4
- 29
- 44