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 8649773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:38:38+00:00 2026-06-12T13:38:38+00:00

So I have the below that will allow me to get xml from one

  • 0

So I have the below that will allow me to get xml from one record in the Products table.

However, I need to to be able to get the XML from ALL records in the Products table, along with its ProductId.

I’m confused on how to start this.

DECLARE @MyXML XML
SET @MyXML =
    (SELECT ProductsXML
     FROM Products
     WHERE ProductId= 1)
SELECT 
    a.b.value('@upccode','int') as UPC,
    a.b.value('@dateadded','date') as DateAdded
FROM
    @MyXML.nodes('xml/Product/UPC')a(b);

I’m using SQL Server 2008.

Test Data:

ProductId: 1
ProductsXML:
<xml>
        <Product>
            <UPC upccode="1237" dateadded="10/9/2012"/>
            <UPC upccode="1236" dateadded="10/8/2012"/>
            <UPC upccode="1235" dateadded="10/7/2012"/>
            <UPC upccode="1234" dateadded="10/6/2012"/>
        </Product>
    </xml>

ProductId: 2
ProductsXML:
<xml>
        <Product>
            <UPC upccode="9876" dateadded="9/9/2012"/>
            <UPC upccode="9877" dateadded="9/8/2012"/>
            <UPC upccode="0998" dateadded="9/7/2012"/>
            <UPC upccode="7877" dateadded="9/6/2012"/>
        </Product>
    </xml>

The Result I’m looking for is something like this:

ProductId      UPC        DateAdded
---------      ---        ---------
1              1237       10/9/2012
1              1236       10/8/2012
....
2              9876       9/9/2012
2              9877       9/8/2012

Right now I can get the above but ONLY by specifying one PoductId at a time. I want to be able to run all of the `Products’ without specifying each entry.

  • 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-06-12T13:38:39+00:00Added an answer on June 12, 2026 at 1:38 pm

    I guess you are looking for something like this.

    SELECT ProductId,
        a.b.value('@upccode','int') as UPC,
        a.b.value('@dateadded','date') as DateAdded
    FROM Products
      CROSS APPLY ProductsXML.nodes('xml/Product/UPC')a(b);
    

    There is no need to have a XML variable in there. Query the Products table directly and use CROSS APPLY against ProductsXML field to shred your XML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below program that will move files from one directory to other.
I have a chart (code to replicate will be below) that has two lines
in my application i have the playvideo page where video will play, below that
I have a page (below) that has a datagrid that lists item's returned from
I have been asked to write a GUI that will allow objects to be
I have a subselect query (like the one below) in my hibernate mapping XML
I have a query below that I use to retrieve the records not updated
I have the below markup that cannot be changed: <div>Some data</div> <span>More data</span> <a>Link
I have the code below that hides and shows the navigational bar. It is
I have this line below that shows a link to go the next page

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.