Когда я запускаю запрос ниже
SELECT
ML.MemberID
,ML.effective_date
,CL.CaseID
,CL.CaseName
,CL.StartDate AS CaseCreatedDate
,CONCAT(U.firstname,' ', U.lastname) AS PrimaryCaseOwner
,CONCAT(U2.firstname,' ', U2.lastname) AS SecondaryCaseOwner
FROM #MemberList ML
INNER JOIN vw_CaseList CL
ON ML.member_id = CL.member_id
AND CL.StartDate < GETDATE()
AND (CL.EndDate IS NULL OR CL.EndDate > GETDATE() )
INNER JOIN Users U ON CL.primary_owner_id = U.[user_id]
LEFT JOIN Cases_SecondaryOwners S ON CL.case_id = S.case_id
LEFT JOIN Users U2 ON S.[user_id] = U2.[user_id]
where MemberID in ( 16468)
ORDER BY MemberName, CaseCreatedDate
Он возвращает это:
MemberID : Effective_Date : CaseID : CaseName : CaseDate : CaseOwner : 2nd Owner
45555 6/2/2019 0002 General 8/11/2019 John A.
45555 7/31/2019 0003 Special 9/1/2019 Jimmy Tyler
45555 7/31/2019 0003 Special 9/1/2019 Jimmy John A.
Но я бы хотел получить такой результат:
MemberID : Effective_Date : CaseID : CaseName : CaseDate : CaseOwner : 2nd Owner1 : 2nd Owner2
45555 6/2/2019 0002 General 8/11/2019 John A.
45555 7/31/2019 0003 Special 9/1/2019 Jimmy Tyler John A.
Как я могу это сделать?Спасибо!