Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to combine values of one column

Author  Topic 

jayanth_jyothi
Starting Member

11 Posts

Posted - 2009-02-13 : 10:24:45
Hi,

For example in one table data is like this


AssociateID RelatedID Relationship
----------- --------- ------------
1234 4567 Passenger
1234 4567 Emergency Contact


So the above data i want make like below

AssociateID RelatedID Relationship
----------- --------- ------------
1234 4567 Passenger,Emergency Contact

Can some body provide me T-SQL for the above case

Thanks in Advance


jayanth_jyothi
Starting Member

11 Posts

Posted - 2009-02-13 : 10:47:51
AssociateID RelatedID Relationship
----------- --------- ------------
1234 4567 Passenger
1234 4567 Emergency Contact


So the above data i want make like below

AssociateID RelatedID Relationship
----------- --------- ------------
1234 4567 Passenger,Emergency Contact

Can some body provide me T-SQL for the above case
as i need to display the grid in above format
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 11:02:46
[code]SELECT DISTINCT t.AssociateID ,t.RelatedID,
STUFF((SELECT ',' + Relationship FROM Table WHERE AssociateID =t.AssociateID AND RelatedID =t.RelatedID FOR XML PATH('')),1,1,'') AS Relationship
FROM Table t
[/code]
Go to Top of Page

jayanth_jyothi
Starting Member

11 Posts

Posted - 2009-02-13 : 12:16:00
Thanks Visakh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 12:36:55
welcome
Go to Top of Page
   

- Advertisement -