Solved

SQL 2008 results to XML multiple namespaces

Posted on 2012-04-11
1
422 Views
Last Modified: 2012-07-11
I have some values in a temp table that I need to export in XML format.  The XML has multiple levels and namespaces which is throwing me off a bit.

This is the data set:
CREATE TABLE #shipments	(	OrderId int,
				dateShippedGMT datetime,
				carrierCode varchar(20),
				classCode varchar(20),
				trackingNumber varchar(50),
				shipmentCost numeric(17,2),
				shipmentTaxCost numeric(17,2))
							

declare @DeveloperKey varchar(100),
	@Password varchar(100),
	@accountID varchar(100)
		
select	@DeveloperKey = '1234567890',
	@Password = '9999',
	@accountID = '54321'	

INSERT #shipments
VALUES (123456, '2012-04-11T12:05:33', 'UPS', 'STD', '314159265358979323', 2.50, 0)

INSERT #shipments
VALUES (234567, '2012-04-11T12:06:13', 'UPS', 'STD', '314159265358979324', 1.50, 0)

SELECT * FROM #shipments
DROP TABLE #shipments

Open in new window

The XML format this needs to be exported to is:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://api.channeladvisor.com/webservices/">
   <soapenv:Header>
      <web:APICredentials>
         <web:DeveloperKey>1234567890</web:DeveloperKey>
         <web:Password>9999</web:Password>
      </web:APICredentials>
   </soapenv:Header>
   <soapenv:Body>
      <web:SubmitOrderShipmentList>
         <web:accountID>54321</web:accountID>
         <web:ShipmentList>
            <web:OrderShipmentList>
               <web:OrderShipment>
                  <web:OrderId>123456</web:OrderId>
                  <web:ShipmentType>Full</web:ShipmentType>
                  <web:FullShipment>
                     <web:dateShippedGMT>2012-04-11T12:05:33</web:dateShippedGMT>
                     <web:carrierCode>UPS</web:carrierCode>
                     <web:classCode>STD</web:classCode>
                     <web:trackingNumber>314159265358979323</web:trackingNumber>
                     <web:shipmentCost>2.50</web:shipmentCost>
                     <web:shipmentTaxCost>0</web:shipmentTaxCost>
                     <web:insuranceCost>0</web:insuranceCost>
                  </web:FullShipment>
               </web:OrderShipment>
               <web:OrderShipment>
                  <web:OrderId>234567</web:OrderId>
                  <web:ShipmentType>Full</web:ShipmentType>
                  <web:FullShipment>
                     <web:dateShippedGMT>2012-04-11T12:06:13</web:dateShippedGMT>
                     <web:carrierCode>UPS</web:carrierCode>
                     <web:classCode>STD</web:classCode>
                     <web:trackingNumber>314159265358979324</web:trackingNumber>
                     <web:shipmentCost>1.50</web:shipmentCost>
                     <web:shipmentTaxCost>0</web:shipmentTaxCost>
                     <web:insuranceCost>0</web:insuranceCost>
                  </web:FullShipment>
               </web:OrderShipment>               
            </web:OrderShipmentList>
         </web:ShipmentList>
      </web:SubmitOrderShipmentList>
   </soapenv:Body>
</soapenv:Envelope>

Open in new window

<web:DeveloperKey> needs to be populated with the variable @DeveloperKey
<web:Password> needs to be populated with the variable @Password
<web:accountID> needs to be populated with the variable @accountID
<web:dateShippedGMT> needs to be populated with #shipments.dateShippedGMT
<web:carrierCode> needs to be populated with #shipments.carrierCode
<web:classCode> needs to be populated with #shipments.classCode
<web:trackingNumber> needs to be populated with #shipments.trackingNumber
<web:shipmentCost> needs to be populated with #shipments.shipmentCost
<web:shipmentTaxCost> needs to be populated with #shipments.shipmentTaxCost

Any help would be appreciated.
0
Comment
Question by:Russell_Harper
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 37832252
While you may be able to use FOR XML EXPLICIT to create that Xml document, it has way too many hierarchies and you would be best advised to use something like .NET to do it.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nested Case statement 4 37
RESTORE A BACKUP IN SQL 2012 from SQL 2008 9 64
Requesting help with creating an SQL query with 2 tables 6 24
SQLCMD Syntax 2 13
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question