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)
 SQL query -Convert multiple rows in one row

Author  Topic 

ckrim
Starting Member

2 Posts

Posted - 2014-10-02 : 13:54:51
Hi all

I'm trying to create SQL query

But I can't convert multiple rows (collections) in one row

I got:

Name Collection Name

ps1 serverDP

ps1 Adobe

ps2 CRT

ps2 Note

I need:

Name Collection Name

ps1 serverDP ,Adobe

ps2 CRT,Note

Im using following query ....but it doesn't work .Need help!!!

select

v_FullCollectionMembership.Name as Name,

CollName = stuff((SELECT '; ' + v_Collection.Name

from

v_Collection

where

v_Collection.CollectionID = v_FullCollectionMembership.CollectionID

FOR

XML PATH('')

), 1, 1,'')

FROM v_FullCollectionMembership

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-02 : 14:29:25
What do you get from your query (error message, results) and what do you actually want to see, given a set of sample data?
Go to Top of Page

ckrim
Starting Member

2 Posts

Posted - 2014-10-02 : 17:18:31
I get following results:

ps1 |serverDP

ps1 |Adobe

ps2 |CRT

ps2 |Note

but I need


ps1 |serverDP ,Adobe

ps2 |CRT,Note

Go to Top of Page
   

- Advertisement -