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 2005 Forums
 Transact-SQL (2005)
 Combine rows in column

Author  Topic 

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-05-11 : 04:28:00
Hi friends,
I have got 3 tables:
Categories: ID | CatName


UserCategories: UserID | ID


UsersData: UserID | ......


A user may have multiple categories
I need the following output

UserID | ..... | Categories


If a user comes under multiple categories, the categories would be seperated by a comma, else it would return the single category.

eg.

user1 |  ..... | cat1, cat2, cat3, cat4

user2 |  ..... | cat1


How do I get this?

Thanks
Peeyush

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-11 : 04:29:32
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-11 : 04:30:11
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx


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

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-11 : 04:30:32



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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-11 : 04:32:03
quote:
Originally posted by khtan

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx


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




Second is not needed as it is posted in SQL Server 2005 forum

Madhivanan

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

- Advertisement -