SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multpile rows in a single row


Multpile rows in a single row

Author
Message
tripri
tripri
SSC Veteran
SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)

Group: General Forum Members
Points: 266 Visits: 454
Hi i got a table which has data like


Table

Col1----col2----Col3
X--------1-------a
X--------1--------b
X--------1--------c
Y--------2-------e
Y--------2--------f
Z--------2-------g
Z--------2-------h



i should get an out put which looks like

col1---col2---col3
x------1------a,b,c
y------2-------e,f
z------2--------g,h


Can any one help me out with this...

Thank you
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14011 Visits: 4639
tripri (8/23/2010)
Hi i got a table which has data like

Table
Col1----col2----Col3
X--------1-------a
X--------1--------b
X--------1--------c
Y--------2-------e
Y--------2--------f
Z--------2-------g
Z--------2-------h

i should get an out put which looks like
col1---col2---col3
x------1------a,b,c
y------2-------e,f
z------2--------g,h

Can any one help me out with this...

Thank you


Is this homework? what do you got so far?

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Tarun Jaggi
Tarun Jaggi
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1687 Visits: 703
Try this....

SELECT DISTINCT c1.Col1, c1.Col2,
STUFF((SELECT ',' + Col3 FROM Tablename c WHERE c.Col1 = c1.Col1 FOR XML PATH('')),1,1,'')
FROM Tablename c1
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search