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 2000 Forums
 SQL Server Development (2000)
 Merge rows of different data

Author  Topic 

adas40
Starting Member

2 Posts

Posted - 2005-08-11 : 15:05:45
ID Topic
59 C++
59 Java
60 VB
61 NULL
78 SQL
78 Perl

Now I want it to look like:

ID Topic
59 C++, Java
60 VB
61 NULL
78 SQL, Perl


Please help. Thanks.

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-08-11 : 15:12:28
Garth's article on coalesce will probably help.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

adas40
Starting Member

2 Posts

Posted - 2005-08-11 : 15:14:40
Yes I saw that post but still have trouble.
The result I got with that post is this.

ID Topic
59,59,60,61,78,78 C++,JAVA,VB.......

Which is not what I want?

Thanks
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-08-11 : 15:32:33
What about doing something like...

SELECT [ID], @TopicList = COALESCE(@TopicList + ', ', '') + CAST(Topic AS varchar(5))
FROM YourTable
GROUP BY [ID]

---------------------------
EmeraldCityDomains.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-12 : 03:14:41
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -