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 2005 Forums
 Transact-SQL (2005)
 can one-to-many joint return coma delimited text ?

Author  Topic 

walank
Starting Member

12 Posts

Posted - 2010-03-10 : 23:01:21
I have 2 tables: table1, table2

table1 has 1 column: my_key (integer, primary key)
table2 has 2 columns: my_key (integer, foreign key), city char(50)

Lets say I have 1 record in table1:
1000
and 3 records in table2:
1000, Chicago
1000, San Diego
1000, Phoenix

I want a query which will return this:
"1000" "Chicago, San Diego, Phoenix"

something like:
SELECT table1.my_key, (SELECT magic_function_here(table2.city) WHERE table2.my_key=table1.my_key) as my_text FROM table1

Any sugesstion how to accomplish this in bare SQL (no stored proc,etc) ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-10 : 23:03:27
see concatenate records without UDF


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -