Sounds like this to me
SELECT ProjectName,
[Role1] AS EMpNameForRole1,
[Role2] AS EMpNameForRole2,
[Role3] AS EMpNameForRole3,..
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY p.[ID] ORDER BY r.[ID]) AS Seq,
p.Description AS ProjectName,
r.Description AS RoleName,
e.ScreenName AS EmpName
FROM Project p
INNER JOIN Project_Role_Assigned pra
ON pra.Project = p.ID
INNER JOIN Project_Role r
ON r.ID= pra.[Role]
INNER JOIN Employee e
ON e.ID = pra.Employee
)t
PIVOT (MAX(ScreenName) FOR RoleName IN ([Role1],[Role2],..))p
You need to put actual role values for Role1,Role2 etc
if you cant determine them beforehand use dynamic sql as below
What you need to understand is that cross tabbing itself is an aggregated operation as you're effectively merging multiple rows
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c
No comments:
Post a Comment