creating nested xml using ms sql query



I've a table T1 with following fields: ID,Surname, Name, BirthDate, BirthPlace, DocNumber, IssueDate. I've created xml by



select * from T1
for XML PATH ('Person')


This created me xml with following format



<Person>
<ID>1</ID>
<SurName>Ivanov</SurName>
...
</Person>
<Person>
...
</Person>
...


This XML contains only one element, which is 'Person', I want to create another element ('Documents') inside this element, similar to:



<Person>
<ID>1</ID>
<SurName>Ivanov</SurName>
...
<Documents>
<DocNumber>1234</DocNumber>
<IssueDate>'20140101'</IssueDate>
</Documents>
</Person>
...


How can I do this? Any suggestions? Thanks in advance.


No comments:

Post a Comment