I'm using SQL Server 2008 R2 Enterprise 64 bit.
My question is:
I have two tables t1 and t2 one has an Id column the other a name column
I can query them so that I get the following result:
ID     Name
1      bob
1      ted
2      bill
3      frank
What I want is the result to look like this:
ID     name
1      bob ted
2      bill
3      frank
The name column can have 1 to n names
What I really need to do is pivot the second column. I have used the cast for xml and stuff functions but these dont really work for what I need.
I tried to write a pivot function but I get an error message.
SELECT ID, name As name   
FROM
(SELECT   ID, name 
 FROM dbo.t1 AS t1 
             INNER JOIN
             dbo.t2 AS t2 ON t1.ID = t2.ID                         
             WHERE  (some filter)
AS s
PIVOT
(
  max(name)
  FOR
  [name]
  IN ( [name]
)) AS p
Thanks in advance :)
 
     
     
    