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)
 Combining multiple columns into one result coumn

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-07-31 : 08:33:18
Darrin writes "Hello...
I’m trying to figure out a way to join two tables (one to many relationship) and have a single record returned. The single record would contain a column that concatenates the foreign keys from the other table...(that’s confusing even when i read it)

currently I get a result set like this:
id  name      productId
--- --------- ---------
1   a         1
1   a         2
1   a         3
2   b         1
2   b         3


Here the id and name column are located in table 1, the productId comes from the second table


I would like the result to be like this
id  name      AllProducts
--- --------- ---------
1   a         1,2,3
2   b         1,3


Any ideas?
Thanks!"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-07-31 : 08:57:34
search here for 'COALESCE' and CSV.

this style of problem has come up many a time before, with appropriate solutions.
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-07-31 : 08:57:42
Converting Multiple Rows into a CSV String (Set Based Method). Make sure to check out byrmol's function in the comments.

Jay White
{0}
Go to Top of Page
   

- Advertisement -