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 |
vijayh143
Starting Member
1 Post |
Posted - 2012-02-13 : 06:19:02
|
Hi All,I have a table structure like this:Table structurePk,fk Pk,fk Pk,fk Pk,fk Pk,fk Pk Value1 Value 2A1 A2 A3 A4 A5 1 xx yyA1 A2 A3 A4 A5 2 xxx yyyA1 A2 A3 A4 A5 3 a bA1 B2 A3 A4 A5 4 aa bbB1 A2 A3 A4 A5 5 aaa bbbB1 B2 B3 B4 B5 6 d eB1 B2 B3 B4 B5 7 dd eeB1 B3 C3 B4 B5 8 ddd eeeIn the above table (pk,fk) constitutes one column and first 6 columns make composite kesy to the table.Now i have to write a query which gives output like this:A1 A2 A3 A4 A5 xx yy xxx yyy a bA1 B2 A3 A4 A5 aa bb B1 A2 A3 A4 A5 aaa bbb B1 B2 B3 B4 B5 d e dd ee B1 B2 C3 B4 B5 ddd eeePlease help me!! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-13 : 10:11:16
|
[code]SELECT Col1,Col2,Col3,Col4,Col5,STUFF((SELECT ',' + Value1 + ' ' + Value2 FROM table WHERE Col1=t.Col1 AND Col2= t.Col2AND Col3 = t.Col3AND Col4 = t.Col4AND Col5 = t.Col5ORDER BY Col6FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT Col1,Col2,Col3,Col4,Col5 FROM Table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|