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
 Transact-SQL (2000)
 creating comma delimited list from a select..

Author  Topic 

VoidPointer
Starting Member

1 Post

Posted - 2005-01-15 : 18:04:46
Hi
I have a stored procedure which returns data from .. let's say USERS table .

Now each user can be in number of departments , and I have connection table - USER_ID - DEPT_ID and
departments table of course.

I need to show a list of users , and one of the fields in this
list is a comma-delimited list of the user departments.

now I have something like this :

SELECT USER_ID , FIRST_NAME , LAST_NAME FROM USERS;

and I have

SELECT DEPARTMENTS.DEPARTMENT_NAME FROM
USER_DEPARTMENTS UD
INNER JOIN DEPARTMENTS ON UD.DEPT_ID=DEPARTMENTS.DEPT_ID

WHERE UD.USER_ID = USERS.USER_ID

the question is how do I combine those , so that the inner select will return me a comma delimited list of department names , and I just return it "AS DEPARTMENT_NAMES" from the main select .

Thanks in advance

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-01-15 : 18:32:58
Have a look at the following article.

http://www.sqlteam.com/item.asp?ItemID=11021

Also in the comments section is a demo of converting this to a udf.
Go to Top of Page
   

- Advertisement -