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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:23:10+00:00 2026-05-22T18:23:10+00:00

I am new to XQuery and am having some problems with it. Here is

  • 0

I am new to XQuery and am having some problems with it. Here is my example.

I have this variable:

declare @xmlDoc XML

it has the following xml stored in it:

<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Sharedparam" type="xs:string" minOccurs="0" />
                <xs:element name="Antoher" type="xs:string" minOccurs="0" />
                <xs:element name="RandomParam2" type="xs:string" minOccurs="0" />
                <xs:element name="MoreParam" type="xs:string" minOccurs="0" />
                <xs:element name="ResultsParam" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table1>
    <Sharedparam>shared</Sharedparam>
    <Antoher>sahre</Antoher>
    <RandomParam2>Good stuff</RandomParam2>
    <MoreParam>and more</MoreParam>
    <ResultsParam>2</ResultsParam>
  </Table1>
  <Table1>
    <Sharedparam>Hey</Sharedparam>
    <Antoher>what </Antoher>
    <RandomParam2>do you</RandomParam2>
    <MoreParam>think</MoreParam>
    <ResultsParam>2</ResultsParam>
  </Table1>
  <Table1 />
</NewDataSet>

How can I select all the values of Sharedparam? (Or really any decent query that returns values (not xml) would be great.)

What I am really looking to do is get a result set like this:

Name             Value1          Value2          Value3        Value4
Sharedparam      shared          Hey             Null          Null
Another          share           what            Null          Null
....

This would have me ignoring any data beyond “Value4” (and that is acceptable for my use of this data).

  • 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-22T18:23:10+00:00Added an answer on May 22, 2026 at 6:23 pm

    Try something like this:

    SELECT
        TBL.SParam.value('(.)[1]', 'varchar(50)')
    FROM
        @xmldoc.nodes('/NewDataSet/Table1/Sharedparam') AS TBL(SParam)
    

    Gives me an output of:

    (No column name)
    shared
    Hey
    

    Update: if you want to get at all the XML elements and their values inside the <Table1> elements, you can use this XQuery:

    SELECT
        TBL.SParam.value('local-name(.)[1]', 'varchar(50)') 'Attribute',
        TBL.SParam.value('(.)[1]', 'varchar(50)') 'Value'
    FROM
        @xmldoc.nodes('/NewDataSet/Table1/*') AS TBL(SParam)
    

    which outputs:

    Attribute            Value
    Sharedparam          shared
    Antoher              sahre
    RandomParam2         Good stuff
    MoreParam            and more
    ResultsParam         2
    Sharedparam          Hey
    Antoher              what 
    RandomParam2         do you
    MoreParam            think
    ResultsParam         2
    

    Update #2: to get the values of the first <Table1> and the second <Table1> XML node next to one another, you need to do two calls to .nodes() – once retrieving the first node, the other time the second one. It gets a bit hairy, especially if you want to extend that even further – and performance is going to be abysmal – but it works 🙂

    SELECT
        TBL.SParam.value('local-name(.)[1]', 'varchar(50)') 'Attribute',
        TBL.SParam.value('(.)[1]', 'varchar(50)') 'Value 1',
        TBL2.SParam2.value('(.)[1]', 'varchar(50)') 'Value 2'
    FROM
        @xmldoc.nodes('/NewDataSet/Table1[1]/*') AS TBL(SParam)
    INNER JOIN
        @xmldoc.nodes('/NewDataSet/Table1[2]/*') AS TBL2(SParam2) ON TBL.SParam.value('local-name(.)[1]', 'varchar(50)') = TBL2.SParam2.value('local-name(.)[1]', 'varchar(50)')
    

    Gives an output of:

    Attribute      Value 1     Value 2
    Sharedparam    shared       Hey
    ResultsParam      2          2
    RandomParam2   Good stuff   do you
    Antoher        sahre        what 
    MoreParam      and more     think
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am having some problems retreiving data from the datastore... I have a
I'm pretty new to XQuery and I'm trying to write an example function that
New to javascript/jquery and having a hard time with using this or $(this) to
I have some code like this : PersistenceManager pm=PMF.get().getPersistenceManager(); String query=select from +PayPal_Message.class.getName()+ where
I'm completely new to XML Schema, XML Stylesheets and XQuery. To me, XML is
If I have several Section elements in an XML document, what XQuery do I
Say I have a Java String which has xml data like so: String content
Hello I have this DatastoreNeedIndexException when I try to order by my query. here
In this JDO, why is .class needed here? Query averageSalaryQuery = pm.newQuery(Employee.class); I would
New to xml. Looking for XPath to search a xml file with python ElementTree

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.