SQL Server FOR XML nesting fragment -


i need produce xml fragment such following

<owner>  <individual>   <name>    <firstname>bob</firstname>    <lastname>smith</lastname>   </name>   <address>    <countrycode>nl</countrycode>    <addressfree>123/456/netherlands/netherlands</addressfree>   </address>  </individual>  </owner>  <owner>  <individual>   <name>    <firstname>tony</firstname>    <lastname>hancock</lastname>   </name>   <address>    <countrycode>us</countrycode>    <addressfree>123/maryland/united states</addressfree>   </address>  </individual> </owner> 

i writing sql:

select     (select            b.givenname [name/firstname] ,          b.familyname [name/lastname] ,          b.address_country [address/countrycode] ,          b.addressfree [address/addressfree]                   dbo.stage_clients_merge b                  b.dwhclientno = @dwhclientno      xml path('individual'), type) xml path('owner'), type; 

but code doesn't return required output, instead wraps both individuals in same owner.

how can change achieve need ?

thanks

in same way have added parents name , address, can add additional parent, 'individual'

select        b.givenname [individual/name/firstname] ,      b.familyname [individual/name/lastname] ,      b.address_country [individual/address/countrycode] ,      b.addressfree [individual/address/addressfree] dbo.stage_clients_merge b b.dwhclientno = @dwhclientno xml path('owner'), type 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -