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 |
tikoti
Starting Member
4 Posts |
Posted - 2013-01-29 : 05:24:42
|
Hi all!I have a questionI have two tables 1-N related e.g.1 car2 bus3 bycicleand a second one with multiple rows for each item in the previous table1 wheels1 seat2 big2 driver2 school3 cheapHow can i obtain with an t-sql statement the following outputcar wheels,seatbus big,driver,schoolbycicle cheaThank you all! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-29 : 05:31:55
|
[code]SELECT t1.description as t1desc,STUFF((SELECT ',' + description FROM table2 WHERE id = t1.id FOR XML PATH('')),1,1,'') AS descriptionsFROM table1 t1[/code]I've assumed column names so make sure you put correct column names instead------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tikoti
Starting Member
4 Posts |
Posted - 2013-01-29 : 05:56:10
|
Wow this is absolutely great!Thank you!quote: Originally posted by visakh16
SELECT t1.description as t1desc,STUFF((SELECT ',' + description FROM table2 WHERE id = t1.id FOR XML PATH('')),1,1,'') AS descriptionsFROM table1 t1 I've assumed column names so make sure you put correct column names instead------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-29 : 05:57:57
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|