Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6537643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:38:28+00:00 2026-05-25T10:38:28+00:00

Hello Im trying to create an xml using sql. my code is as follows:

  • 0

Hello Im trying to create an xml using sql. my code is as follows:

SELECT
    --so.SalesOrderID,
    --so.name as 'OrderName',
    so.zon_cartid as "zcom_order_id",
    c.zon_emailaddress1 As "email",
    so.OrderNumber,
    so.createdon As "created",
    so.totallineitemamount As "Sub_total",
    so.totalamount as "Order_total",
    so.totaltax As "oder_tax",
    so.[description] As "Order_note",
    so.zon_ordersubsource as "order_source",
    so.submitstatus As "order_status",
    so.discountamount As "order_discount",
    --c.FirstName,
    --c.LastName,
    --a.name as 'AccountName',
   (SELECT --sod.SalesOrderDetailID,
        p.zon_isbn10,
        sod.Zon_producttype,
        --p.Zon_title,
        --sod.Zon_status,
        SOD.Quantity As "Quantity", 
       SOD.PricePerUnit As "Price",
       SOD.Tax As "Tax",
       SOD.ManualDiscountAmount As "Product_discount"
       --sod.extendedamount
    FROM SalesOrderDetail sod
    inner join Product p on sod.productid = p.productid
    WHERE so.SalesOrderId = sod.SalesOrderId
    ORDER by sod.SalesOrderDetailID
    FOR XML PATH('Product'),Type) As "Products", 
    (Select so3.ShippingMethodCode,
                  so3.freightamount, 
    (Select    c.firstname,
                     c.lastname, 
               so2.Shipto_Line1,
               so2.Shipto_Line2,
               so2.Shipto_Line3,
               so2.Shipto_City As "city",
               so2.Shipto_StateorProvince As "state",
               so2.Shipto_PostalCode As "postal",
               so2.shipto_country As "country",
               so2.Shipto_telephone As "phone",
               so2.Shipto_fax As "fax"
              From SalesOrder so2
              WHERE so2.SalesOrderId = so.SalesOrderId
             FOR XML PATH(''),Type) As "ShippingAddress" 
              From SalesOrder so3
              WHERE so3.SalesOrderId = so.SalesOrderId
              FOR XML PATH(''),Type),
   (Select     c.firstname,
               c.lastname, 
               so4.billto_Line1,
               so4.billto_Line2,
               so4.billto_Line3,
               so4.billto_City As "city",
               so4.billto_StateorProvince As "state",
               so4.billto_PostalCode As "postal",
               so4.billto_country As "country",
               so4.billto_telephone As "phone",
               so4.billto_fax As "fax"
              From SalesOrder so4
              WHERE so4.SalesOrderId = so.SalesOrderId
             FOR XML PATH(''),Type) As "MailingAddress"
FROM SalesOrder so
left outer join Contact c on c.contactid = so.customerid 
left outer join Account a on a.accountid = so.customerid
WHERE so.CreatedOn > '2011-08-08'
FOR XML PATH('Order'),ROOT('message')

my output looks liek this:

<message>
  <Order>
    <OrderNumber>ORD-01003-H8M0J</OrderNumber>
    <created>2011-08-16T13:52:48</created>
    <Sub_total>233.9400</Sub_total>
    <Order_total>228.4400</Order_total>
    <oder_tax>2.5000</oder_tax>
    <order_source>The Story</order_source>
    <order_discount>8.0000</order_discount>
    <Products>
      <Product>
        <zon_isbn10>0310591635</zon_isbn10>
        <Quantity>10.0000000000</Quantity>
        <Price>4.0000</Price>
      </Product>
      <Product>
        <zon_isbn10>0310649781</zon_isbn10>
        <Quantity>3.0000000000</Quantity>
        <Price>43.9800</Price>
        <Tax>1.4000</Tax>
        <Product_discount>10.0000</Product_discount>
      </Product>
      <Product>
        <zon_isbn10>031023414X</zon_isbn10>
        <Quantity>4.0000000000</Quantity>
        <Price>20.0000</Price>
        <Tax>1.1000</Tax>
        <Product_discount>8.0000</Product_discount>
      </Product>
    </Products>
    <ShippingAddress>
      <Shipto_Line1>1211 E BADILLO ST</Shipto_Line1>
      <Shipto_Line3>WEST COVINA CA 91790</Shipto_Line3>
      <postal>91790</postal>
    </ShippingAddress>
    <MailingAddress></MailingAddress>
  </Order>

but my required output is it should show the basic details in the order as order header as shown below i tried all different ways but iam missing something if someone can help that would be great.

<message>
  <Order>
<orderheader>
    <OrderNumber>ORD-01003-H8M0J</OrderNumber>
    <created>2011-08-16T13:52:48</created>
    <Sub_total>233.9400</Sub_total>
    <Order_total>228.4400</Order_total>
    <oder_tax>2.5000</oder_tax>
    <order_source>The Story</order_source>
    <order_discount>8.0000</order_discount>
</orderheader>
    <Products>
      <Product>
        <zon_isbn10>0310591635</zon_isbn10>
        <Quantity>10.0000000000</Quantity>
        <Price>4.0000</Price>
      </Product>
      <Product>
        <zon_isbn10>0310649781</zon_isbn10>
        <Quantity>3.0000000000</Quantity>
        <Price>43.9800</Price>
        <Tax>1.4000</Tax>
        <Product_discount>10.0000</Product_discount>
      </Product>
      <Product>
        <zon_isbn10>031023414X</zon_isbn10>
        <Quantity>4.0000000000</Quantity>
        <Price>20.0000</Price>
        <Tax>1.1000</Tax>
        <Product_discount>8.0000</Product_discount>
      </Product>
    </Products>
    <ShippingAddress>
      <Shipto_Line1>1211 E BADILLO ST</Shipto_Line1>
      <Shipto_Line3>WEST COVINA CA 91790</Shipto_Line3>
      <postal>91790</postal>
    </ShippingAddress>
    <MailingAddress></MailingAddress>
  </Order>

Thanks in advance
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:38:29+00:00Added an answer on May 25, 2026 at 10:38 am

    You can write the alias for the items you need in orderheader as ‘orderheader/created’ and so on to get the desired output.

    SELECT
    so.OrderNumber as 'orderheader/OrderNumber',
    so.createdon As 'orderheader/created',
    so.totallineitemamount As 'orderheader/Sub_total',
    so.totalamount as 'orderheader/Order_total',
    ...
    

    will produce the output as

    <orderheader>
        <OrderNumber>something</OrderNumber>
        <created>something</created>
        <Sub_total>something</Sub_total>
        <Order_total>something</Order_total>
    </orderheader>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm trying to insert some XML data into a table on SQL Server
I am trying to create a two view, single controller application as follows: I
I am trying to create a magento shopping cart module but things arent working
I am trying to create a small function that returns the number of spaces
I'm trying to create something like a MDI tabbed Interface so I have a
I'm trying to create a chaining function for working with strings that are returned
I'm trying to serve a word document (docx) from an asp.net page using the
I’m trying to write a twitter program to get my tinme line. I’m using
I am trying to create a LinearLayout with TextViews in Java, because the number
I am using Eclipse Indigo, testing on 2 emulators(2.2 and 3.0). the code below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.