Наконец мне удалось получить вывод с помощью запроса ниже.
DECLARE @T TABLE
(
EmployeeID INT NOT NULL
,Objective NVARCHAR(250)
, ObjectiveWeightage DECIMAL(6,4) NOT NULL
)
INSERT INTO @T
(EmployeeID, Objective, ObjectiveWeightage)
VALUES (1, 'A', 5 )
, (1, 'B', 10 )
, (1, 'C', 15 )
, (1, 'D', 20 )
, (1, 'E', 5 )
, (1, 'F', 51 )
;WITH CTE_Rank AS
(
SELECT EmployeeID
, Objective
, ObjectiveWeightage
, sObjective = 'Objective' + CAST(DENSE_RANK() OVER (PARTITION BY EmployeeID ORDER BY Objective) AS VARCHAR(10))
, sObjectiveWeightage = 'ObjectiveWeightage' + CAST(DENSE_RANK() OVER (PARTITION BY EmployeeID ORDER BY Objective) AS VARCHAR(10))
FROM @T
)
SELECT EmployeeID
,MAX( Objective1) Objective1
,MAX( ObjectiveWeightage1)ObjectiveWeightage1
,MAX( Objective2 )Objective2
,MAX( ObjectiveWeightage2)ObjectiveWeightage2
,MAX( Objective3 )Objective3
,MAX( ObjectiveWeightage3)ObjectiveWeightage3
,MAX( Objective4 )Objective4
,MAX( ObjectiveWeightage4)ObjectiveWeightage4
,MAX( Objective5 )Objective5
,MAX( ObjectiveWeightage5)ObjectiveWeightage5
,MAX( Objective6 )Objective6
,MAX( ObjectiveWeightage6)ObjectiveWeightage6
,MAX( Objective7 )Objective7
,MAX( ObjectiveWeightage7)ObjectiveWeightage7
,MAX( Objective8 )Objective8
,MAX( ObjectiveWeightage8)ObjectiveWeightage8
,MAX( Objective9 )Objective9
,MAX( ObjectiveWeightage9)ObjectiveWeightage9
,MAX( Objective10 )Objective10
,MAX( ObjectiveWeightage10)ObjectiveWeightage10
FROM CTE_Rank AS R
PIVOT(MAX(Objective) FOR sObjective IN ([Objective1], [Objective2], [Objective3], [Objective4],[Objective5],[Objective6],[Objective7],[Objective8],[Objective9],[Objective10])) AS EmployeeObjective
PIVOT(MAX(ObjectiveWeightage) FOR sObjectiveWeightage IN (ObjectiveWeightage1, ObjectiveWeightage2, ObjectiveWeightage3, ObjectiveWeightage4,ObjectiveWeightage5,ObjectiveWeightage6,ObjectiveWeightage7,ObjectiveWeightage8,ObjectiveWeightage9,ObjectiveWeightage10)) AS EmployeeObjectiveWeightage
GROUP BY EmployeeID