试图找出如何使用JSON路径表达式创建子数组

时间:2017-10-05 07:56:34

标签: sql-server sql-server-2016 jsonpath

需要有关如何使用以下模式使EmailId成为具有JSON路径表达式的EventId子数组的指导:

http://sqlfiddle.com/#!6/8f8ecc/2

1 个答案:

答案 0 :(得分:0)

你可以使用它。

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