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 |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2008-10-09 : 02:02:17
|
| One of my table contains dataRoomNo Equipment====== =========1 CPU1 MONITOR1 PRINTER2 FAX2 PROJECTORI need a query which can give me results in following formatRoomNo Equipments====== ==========================1 CPU,MONITOR,PRINTER2 FAX,PROJECTOR(I DON'T WANT TO USE CURSOR FOR THIS PURPOSE)Thanx in advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-09 : 02:10:32
|
| [code]SELECT t.RoomNo,LEFT(el.EquipList,LEN(el.EquipList)-1)FROM (SELECT DISTINCT RoomNo FROM yourtable) tCROSS APPLY (SELECT Equipment + ',' AS [text()] FROM YourTable WHERE RoomNo=t.RoomNo FOR XML PATH(''))el(EquipList)[/code] |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2008-10-09 : 02:27:18
|
| thanx a lot Mr. Genius |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-09 : 02:34:02
|
quote: Originally posted by lionofdezert thanx a lot Mr. Genius
welcome |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-09 : 03:03:51
|
Visakh, may I ask why you have "AS [text()]" in the CROSS APPLY derived table, when you also name the derived table and column with "AS el(EquipList)"? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|