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
 General SQL Server Forums
 New to SQL Server Programming
 merge rows of same ID

Author  Topic 

JennZ
Starting Member

3 Posts

Posted - 2012-05-23 : 06:27:24

Hello..
I've been stuck in this problem for long. I have a table (tbl_Artist) with columns (ID, JobID, Name) where ID is unique. say for example:
ID JobID Name
1 1001 artist1
2 2091 artist3
3 1001 artist2

I want to achieve:
ID JobID Name
1 1001 artist1, artist2
2 2091 artist2


Any help would be appreciated..

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-23 : 06:30:46
use the for xml path method describe here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

JennZ
Starting Member

3 Posts

Posted - 2012-05-23 : 06:32:51
thank you for your reply! :)
does it work in vb.net?

(sorry for my asking, i'm new in programming)
Go to Top of Page

JennZ
Starting Member

3 Posts

Posted - 2012-05-23 : 07:44:52
I found this example from
http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

SELECT DISTINCT CategoryId, ProductNames
FROM Northwind.dbo.Products p1
CROSS APPLY ( SELECT ProductName + ','
FROM Northwind.dbo.Products p2
WHERE p2.CategoryId = p1.CategoryId
ORDER BY ProductName
FOR XML PATH('') ) D ( ProductNames )


how does it work?

I get error on SELECT..
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-23 : 07:58:34
quote:
I get error on SELECT..


Can you show us your query ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -