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
 General SQL Server Forums
 New to SQL Server Programming
 Get multiple row values for each selected row

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2010-06-11 : 15:55:03
I need to get multiple row values from a table, concatenated together for each row of the SELECT query.
Here is the table structures:
1) MY_DATA - Data_ID(PK), Data_Num(FK, Numeric),...
2) FLAG_MYDATA_XREF - Flag_Data_Num,Flag_Param,Flag_Method,Flag_Flag (all of them makes the combined primary key)

The Select should join these two tables(ON Data_Num = Flag_Data_Num) and for each row in the First table, get all the Flag_Flags concatenated together from the matching rows in the 2nd table.
Any idea?
Thanks.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-06-11 : 16:01:19
There are a number of techniques listed and compared here:

http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

My personal favorite uses the FOR XML PATH keyword.
Go to Top of Page
   

- Advertisement -