Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL 2008 results to XML multiple namespaces

Posted on 2012-04-11
Medium Priority
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="" xmlns:web="">

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.
Question by:Russell_Harper
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 75

Accepted Solution

Anthony Perkins earned 1500 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.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

704 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