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 |
|
rams.enjamuri
Starting Member
2 Posts |
Posted - 2011-10-26 : 17:10:35
|
| Table1Table1Id Table1Name Table1Phone501 AAAAA 1111111111502 BBBBB 2222222222503 CCCCC 3333333333----------------------------------Table2Table2Id Table2Name1 abc 2 def 3 ghi ----------------------------------Table3Table1Id Table2Id501 1501 2501 3502 1502 2503 1503 3----------------------------------output as belowTable1Name Table2Name Table1PhoneAAAAA abc, def, ghi 1111111111BBBBB abc, def 2222222222CCCCC abc, ghi 3333333333I want to display with comma seperte in front end(gridview), is possible with a query and bind to gridview or get the values and do some coding in c#could anyone help in this regardThanks in advance!!!!!!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-27 : 02:37:13
|
| [code]SELECT t1.Table1Name,STUFF((SELECT ',' + Table2Name FROM Table2 WHERE Table2Id = t3.Table2Id ORDER BY Table2Id FOR XML PATH('')),1,1,'') AS Table2Names,t1.Table1Phone FROM Table3 t3INNER JOIN Table1 t1ON t1.Table1Id = t3.Table1Id [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
rams.enjamuri
Starting Member
2 Posts |
Posted - 2011-10-27 : 10:09:59
|
quote: Originally posted by visakh16
SELECT t1.Table1Name,STUFF((SELECT ',' + Table2Name FROM Table2 WHERE Table2Id = t3.Table2Id ORDER BY Table2Id FOR XML PATH('')),1,1,'') AS Table2Names,t1.Table1Phone FROM Table3 t3INNER JOIN Table1 t1ON t1.Table1Id = t3.Table1Id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I am sorry!!!I forgot to mention, I am using DB2 not SQL server |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-27 : 10:15:42
|
| Try a db2 forum then.You get CTEs in DB2 which can be used in a similar way.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|