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 |
|
aravindt77
Posting Yak Master
120 Posts |
Posted - 2008-11-20 : 00:23:59
|
| Hi,SELECT * from Stud_PlacesRolNo Place-----------------1 Dubai1 Kuwait1 Paris2 London2 Texas3 Los Angels3 Germany3 FranceI want the result to be like thisRolNo Places------------------1 Dubai , Kuwait , Paris2 London , Texas3 Los Angels , Germany , Francecan any one suggest a T-SQL statement for this ???RegardsARV |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-11-20 : 00:47:45
|
| Try thisdeclare @tbl as table(rollno int,places varchar(20))insert into @tblselect 1,'Dubai' union allselect 1,'Kuwait' union allselect 1,'Paris' union allselect 2,'London' union allselect 2,'Texas' select rollno, (select places + ',' from @tbl t1 where t1. rollno =t2. rollno for xml path(''))from @tbl t2 group by rollno |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 01:15:02
|
slight modification to remove extra , in endselect rollno, stuff((select ','+ places from @tbl t1 where t1. rollno =t2. rollnofor xml path('')),1,1,'')from @tbl t2 group by rollno |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|
|
|