auto generate XML using SQL- How to get a outer tag around a group of similar items without using root()? -



auto generate XML using SQL- How to get a outer tag around a group of similar items without using root()? -

ideally, xml file looks below, far query not generate tag orderrequests, orderrequest. below query have used , xml needs generated.

query:

declare @xml xml; declare @requestfileheader table ( clientcode varchar(10), createtime varchar(40), batchnumber int ); insert @requestfileheader values('cmg','2013-09-16t00:20:13.7306775-07:00', cast(rand() * 1000000 int) ) select requestfileheader.*, orderrequest.transactiontime, (orderrequest.referencenumber -1000000+ cast(rand() *1000000 int)) referencenumber, 'false' isrush, shippingaddress.* @requestfileheader requestfileheader, rbcrequest orderrequest, rbcordershippingaddress shippingaddress-- , rbcrequest orderrequests (shippingaddress.requestid = orderrequest.requestid) xml auto , root('transactionrequest'), elements go xml: <orderrequests> <orderrequest> <referencenumber>647433081</referencenumber> <transactiontime>2014-04-07t04:35:00</transactiontime> <isrush>false</isrush> <shippingaddress> <name>roger rai</name> <address1>18855 54a ave</address1> <address2 /> <address3 /> <city>surrey</city> <province>bc</province> <postalcode>v3s6r4</postalcode> <homephone>6046008564</homephone> <businessphone>6047247883</businessphone> </shippingaddress> <programtype>av</programtype> <comments /> <items> <item> <sku>cc03327-slv</sku> <productcode>aa1346</productcode> <quantity>1</quantity> </item> </items> </orderrequest>

embed query have in query creates root node. need add together type directive existing query.

class="lang-sql prettyprint-override">select ( -- replace existing query. select * t xml auto, root('orderrequest'), elements, type ) xml path('orderrequests')

sql xml

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -