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)
 Comma list from table

Author  Topic 

PlasticLizard
Starting Member

7 Posts

Posted - 2004-12-17 : 17:03:36
Hello,

I am attempting to include a comma-delimited list in a select statement where the comma list is a concatenation of a column in a rowset. Here is essentially what I need to do, pretending the functionality I want could be build into a UDF:

Select
dbo.GetCommaListFromRowset('Select SelectedOption from MySelections WHERE ParentID = @MyRecords_ID',MyRecords.ID) as FullSelectionString,
SomeField1,
SomeField2

From MyRecords

The table structurs is like the

MyRecords
---------
ID
SomeField1
SomeField2

MySelections
------------
ParentID
SelectedOption

Where MySelections.ParentID is reference to the MyRecords.ID of the record the particular selection belongs to.

I have looked into all sorts of uses of sp_executesql, but I really need this comma list to be inlined into a select statement. I am building dynamic queries where the exact tables I need to delimit are unknown at design time.

Thanks for any suggestions,
Nathan Stults

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-17 : 17:22:50
You don't have to pretend:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=19647
http://www.sqlteam.com/item.asp?ItemID=11021

Although I don't think you'll be able to get a UDF to dynamically handle variable table names. I would say you'll probably be better off with stored procedures for this kind of thing.
Go to Top of Page
   

- Advertisement -