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 |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2009-03-30 : 04:49:03
|
HiI have a table that looks like this..MachineNo Rowno sectionID Mtype123 20 11111 22456 20 11111 22789 30 22222 33122 30 22222 33 Then I run a query where based on "RowNo" and "SectionID", but I want to group the result so that the result looks like this..MachineNo Rowno sectionID Mtype123, 456 20 11111 22789, 122 30 22222 33 How do I group them together? |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2009-03-30 : 05:51:17
|
| DECLARE @tab table (MachineNo INT , Rowno INT, sectionID INT , Mtype INT)INSERT INTO @Tab (MachineNo , Rowno , sectionID , Mtype )SELECT 123 , 20 , 11111 , 22 union allSELECT 456 , 20 , 11111 , 22 union allSELECT 789 , 30 , 22222 , 33 union allSelect 122 , 30 , 22222 , 33SELECT DISTINCT (SELECT CONVERT(VARCHAR,MachineNo)+',' AS 'data()' FROM @tab t2WHERE t2.Rowno=t1.RowNoFOR XML PATH ('')) Machines ,Rowno,SectionID,MtypeFROM @tab t1 |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2009-03-30 : 06:54:44
|
| HiI get a syntax error near "xml" |
 |
|
|
|
|
|
|
|