Click here to Skip to main content
14,691,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I need a query for below for sql server 2000.

table structure:

col1 Col2
1 a
2 b
1 c
2 d
1 e
3 f

Out put should be like this:

col1 col2
1 a,c,e
2 b,d
3 f

Help me on this.

Espen Harlinn 1-Oct-11 13:18pm
I really enjoyed your profile - it's a shame I can't vote for it too :)
Kim Togo 2-Oct-11 11:17am
Haha thanks :-)
Must confess that the original text is her:
Try this.
SELECT   Col1, LEFT([Col2], LEN([Col2]) - 1) as [Col2]
           FROM  ( SELECT  DISTINCT Col1
                      FROM  tablename )  AS A

                FROM  tablename B WHERE A.Col1 = B.Col1
                 FOR  XML PATH('') ) AS C ([Col2])

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900