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

  • SEARCH
  • Home
  • 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 7130131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:19:02+00:00 2026-05-28T11:19:02+00:00

Could anyone tell me how I could select values from the following xml: I

  • 0

Could anyone tell me how I could select values from the following xml:
I would like to get rows as follows:
Col1: key, Col2: key, Col3: value

1 1 value
1 2 value2
1 3 value3

2 4 value4
2 5 value5
2 6 value6

Here is the xml:

<root>
  <item>
    <key>1</key>
    <value>
      <params>
        <item>
          <key>1</key>
          <value>value</value>      
        </item>
        <item>
          <key>2</key>
          <value>value2</value>     
        </item>     
        <item>
          <key>3</key>
          <value>value3</value>     
        </item>     
      </params>
    </value>
  </item>
  <item>
    <key>2</key>
    <value>
      <params>
        <item>
          <key>4</key>
          <value>value4</value>     
        </item>
        <item>
          <key>5</key>
          <value>value5</value>     
        </item>     
        <item>
          <key>6</key>
          <value>value6</value>     
        </item>     
      </params>
    </value>
  </item>  
</root>
  • 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-28T11:19:03+00:00Added an answer on May 28, 2026 at 11:19 am

    Assuming you have this XML in a T-SQL variable – then you could use this snippet of code:

    DECLARE @input XML = '...(your XML here).....'
    
    SELECT
        Key1 = Item.value('(key)[1]', 'int'),
        Key2 = Item2.value('(key)[1]', 'int'),
        ItemValue = Item2.value('(value)[1]', 'varchar(50)')
    FROM 
        @input.nodes('/root/item') AS T(Item)
    CROSS APPLY
        item.nodes('value/params/item') AS T2(Item2)
    

    This gives me an output of:

    Key1  Key2  ItemValue
     1     1     value
     1     2     value2
     1     3     value3
     2     4     value4
     2     5     value5
     2     6     value6  
    

    The approach is the following:

    • grab the list of <item> nodes under <root> as your first “list of XML nodes” with the first .nodes() XQuery method, and extract the value of the <key> XML element in that XML fragment into Key1

    • grab the “nested” list of XML nodes inside that XML fragment, using the value/params/item XPath, to get the child rows – and extract the values from <key> and <value> from those nested child XML fragments into Key2 and ItemValue

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

Sidebar

Related Questions

Could anyone tell me how to bulk insert data from a ref cursor to
Could anyone please tell me why the following line about filter init method invocation
could anyone tell me how to select particular column if i dont know the
could anyone please tell me what is wrong this this code? I get a
could anyone tell me the difference between Terminal and non-terminal symbol in the case
Could anyone tell me if it is possible to use the flex 4 framework
Could anyone tell me if SQL Server 2008 has a way to prevent keywords
Could anyone tell me how to make RTC generate periodic interrupts? Here's what I
Here's the code, I don't quite understand, how does it work. Could anyone tell,
Could anyone can tell me where I can find full ASP.NET MVC beta documentation?

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.