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 2008 Forums
 Transact-SQL (2008)
 Concanate Value

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2011-11-18 : 01:15:25
Dear ALl,

I have

Ref Sub-Ref Type
OP13346 OP13346/1 CustServ
OP13346 OP13346/2 Counter
OP13346 OP13346/3 Serv
OP13346 OP13346/4 CustServ
OP13346 OP13346/5 Serv
OP13347 OP13347/2 Cust
OP13347 OP13347/3 Cust

I want concanate the Type based on Ref#
Ref Sub-Ref Type ConcanateType
OP13346 OP13346/1 CustServ CustServ,Counter,Serv
OP13346 OP13346/2 Counter CustServ,Counter,Serv
OP13346 OP13346/3 Serv CustServ,Counter,Serv
OP13346 OP13346/4 CustServ CustServ,Counter,Serv
OP13346 OP13346/5 Serv CustServ,Counter,Serv
OP13347 OP13347/2 Cust Cust
OP13347 OP13347/3 Cust Cust


Please Advise.

Thank you.


Regards,
Micheale

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-18 : 01:33:14
[code]
SELECT *,STUFF((SELECT ',' + Type FROM table WHERE Ref = t.Ref ORDER BY [Sub-Ref] FOR XML PATH('')),1,1,'') AS ConcatenateType
FROM Table t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -