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
Post a Comment