Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Multpile rows in a single row Expand / Collapse
Author
Message
Posted Monday, August 23, 2010 4:31 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, December 5, 2014 1:27 PM
Points: 82, Visits: 354
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
Post #973776
Posted Monday, August 23, 2010 4:42 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
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.
Post #973778
Posted Wednesday, August 25, 2010 2:17 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, December 13, 2014 2:10 AM
Points: 1,231, Visits: 577
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
Post #974681
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse