У меня следующий запрос, который возвращает мне другой IBAN для EmployeeId = 54:
WITH cte AS ( SELECT TOP 1000 [E].[EmployeeId]
,(CASE WHEN BIT.Label='Salary' THEN [BI].[IBAN] END) AS IBAN_Salary
,(CASE WHEN BIT.Label='Expenses Claims' THEN [BI].[IBAN] END) AS IBAN_Expenses_Claims
,bi.UpdatedDate
, ROW_NUMBER() OVER (PARTITION BY E.EmployeeId,bit.Label ORDER BY BI.UpdatedDate DESC) rn
FROM [Employee] AS [E]
LEFT JOIN [AF_AdminFile] AS [AAF] ON [AAF].[AdminFileId] = [E].[AdminFileId]
LEFT JOIN [AF_BankInformation] AS [AFB] ON [AFB].[AdminFileId] = [AAF].[AdminFileId]
LEFT JOIN [BankInformation] AS [BI] ON [BI].[BankInformationId] = [AFB].[BankInformationId]
LEFT JOIN [BankInformationType] AS [BIT] ON [BIT].[BankInformationTypeId] = [AFB].[BankInformationTypeId]
LEFT JOIN [BankInformationSystem] AS [BIS] ON [BIS].[BankInformationSystemId]=[BI].[BankInformationSystemId]
LEFT JOIN [Currency] AS [Cur] ON [Cur].[ID]=[BI].[CurrencyId]
WHERE BIT.BankInformationTypeId IN (1,2)
AND e.EmployeeId=54
GROUP BY e.EmployeeId, BIT.Label,BI.UpdatedDate,BI.IBAN
ORDER BY e.EmployeeId
)
SELECT * FROM cte WHERE rn =1
Вывод предыдущего запроса:
Как получить отдельный столбец для IBAN_Salary, IBAN_Expenses_Claims, updatedDated_IBAN_Salary, UpdatesDated_IBAN_Expenses_Claims в той же строке, как показано ниже?:
EmployeeId IBAN_Salary IBAN_Expenses_Claims UpdatedDated_IBAN_Salary UpdatedDated_IBAN_Expenses_Claims
54 lorem ipsum lorem ipsum 2019-08-09 09:38:00.7350889 2018-07-07 17:09:16.7598906