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 |
swanandbagve
Starting Member
2 Posts |
Posted - 2014-01-23 : 01:08:38
|
Assume i have 3 tablesPerson(personname,age)Children(childname,personname)car(carname,personname)A persone can have multiple carsA person can have multiple childrenIts not possible to display the results in SQL rowsand columns.If one tries to it will givePersonName Carname ChildnameSachin Audi C1Sachin Maruti C1Sachin Audi C2Sachin Maruti C2Instead of writing seperate queries the application wantsto receive an xml output as follows<person><pname>sachin</pname><car>audi</car><car>bmw</car><cname>c1</cname><cname>c2</cname><person>How to get this output ? |
|
swanandbagve
Starting Member
2 Posts |
Posted - 2014-01-23 : 02:26:08
|
I solved my own query using nesting :) SELECT person.name, (select vname from vehicle where vehicle.name=person.name FOR XML AUTO, TYPE), ( SELECT cname FROM children WHERE children.name = person.name FOR XML AUTO, TYPE)FROM personFOR XML AUTO, TYPE; |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|