Sunday, June 29, 2014

Unpivot, Pivot without Aggregation

Few other methods


Using UNPIVOT



declare @t table
(
Eventname varchar(100),
Eventmanager varchar(100),
Staff varchar(100),
Volunteer varchar(100)
)

INSERT @t
VALUES ('Fundrive','Mr.Z','Xyz1','Abc1'),
('Fundrive','Mr.Z','Xyz2','Abc2'),
('Fundrive','Mr.Z','Xyz3','Abc3')

SELECT DISTINCT JobDescription,Name
FROM @t t
UNPIVOT (Name FOR JobDescription IN ([Eventmanager],[Staff],[Volunteer]))u
ORDER BY JobDescription,Name



Using VALUES clause



SELECT DISTINCT JobDescription,Name
FROM @t t
CROSS APPLY (VALUES('Eventmanager',[Eventmanager]),('Staff',[Staff]),('Volunteer',[Volunteer]))u(JobDescription,Name)







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