There are better ways to do this, and 5 miuntes after I post this Peso and/or Visakh will show you how!
DECLARE @Table TABLE ( uid int ,firstName varchar(50) ,destination varchar(50) )INSERT INTO @Table SELECT 123, 'Jim','Alaska' UNION ALLSELECT 123, 'Jim','Kansas' UNION ALLSELECT 123, 'Jim','Texas' UNION ALLSELECT 521, 'Maggy','Virginia' UNION ALLSELECT 521, 'Maggy','Idaho' UNION ALLSELECT 510, 'Kerry','Florida' UNION ALLSELECT 510, 'Kerry','Georgia' UNION ALLSELECT 510, 'Kerry','Kansas' UNION ALLSELECT 981, 'Dave','California' UNION ALLSELECT 981, 'Dave','Washington' UNION ALLSELECT 981, 'Dave','Texas' UNION ALLSELECT 981, 'Dave','Illinois' SELECT t2.uid,t2.firstName ,[destinationOne] = MAX(t2.destinationOne) ,[destinationTwo] = MAX(t2.destinationTwo) ,[destinationThree] = MAX(t2.destinationThree) ,[destinationFour] = MAX(t2.destinationFour) FROM ( select t1.uid ,t1.firstname ,[destinationone] = case when t1.row= 1 then t1.destination else null end ,[destinationtwo] = case when t1.row= 2 then t1.destination else null end ,[destinationthree] = case when t1.row= 3 then t1.destination else null end ,[destinationfour] = case when t1.row= 4 then t1.destination else null end from ( select uid,firstName,destination,[Row] = ROW_NUMBER() OVER (partition by uid,firstname order by uid) from @table ) t1 ) t2GROUP BY t2.uid,t2.firstNameORDER BY uid
Jim