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.
| Author |
Topic |
|
00kevin
Yak Posting Veteran
78 Posts |
Posted - 2008-11-07 : 11:44:27
|
| Can anyone here point me to a stored procedure or function that will create a comma separated list out of the rows of a table?For exampleI have a table called Car and a 1-N relationship to another table called Parts. I want to return a single result set with all the rows in the parts table that belong to Car as a comma separated list. The comma separated list should be in a single field.selectcar_id,car_name,some_function(car_id) as car_parts_list , -- some function that I can pass the car_id from car |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 11:50:35
|
| [code]selectcar_id,car_name,left(pl.partslist,len(pl.partslist)-1)from car ccross apply (select partsfield + ',' from parts where car_id=c.car_id for xml path(''))pl(partslist)[/code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|