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)
 Getting CSV for a subquery

Author  Topic 

nmg196
Yak Posting Veteran

70 Posts

Posted - 2001-08-01 : 13:32:09
Is there a way to get SQL Server to return a comma seperated list of ID's in a subquery?


SELECT CompanyName,
(SELECT CompanyType
FROM CompaniesToTypes
WHERE CompanyID = 21426) AS Types
FROM ....[blah]


But it fails if the subquery returns more than one row.

I'm looking for an output like:


ID Name Type
1 "Nick's Company" "A,B,C"
2 "Fred PLC" "A,C,T,Y"
3 "Mark Ltd" "B"


But I can't seem to find a way of doing it...

Has anyone got any ideas?

This is mainly important because of the way the rest of the query works - otherwise I'd just get the list at the application level.

Thanks!

Nick...


Edited by - nmg196 on 08/01/2001 13:34:24
   

- Advertisement -