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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:40:41+00:00 2026-06-09T19:40:41+00:00

I am trying to query an xml column among other…the following query is working

  • 0

I am trying to query an xml column among other…the following query is working fine…

SELECT
            OrderID,
            AccountNumber, 
            ItemID,
            substring(replace(lower(s.Street),' ',''),1,8) 
                + substring(replace(lower(s.City),' ',''),1,8) 
                + substring(replace(lower(s.State),' ',''),1,8) 
                + substring(replace(s.ZipCode,' ',''),1,5)AddressHash,
            ShipName,
            Street,
            Street2
            City,
            State,
            ZipCode,
            OrderDate
    FROM   (SELECT UpwardOrderID, AccountNumber, UpwardLeagueID,
                    /* NOTE THAT THIS SYNTAX WORKS ONLY WORKS BECAUSE THE NODES ARE SINGLETONS. */
                   x.value('(./ShipTo/Name)[1]', 'VARCHAR(255)')                                                AS ShipName,
                   x.value('(./ShipTo/Street1)[1]', 'VARCHAR(255)')                                             AS Street,
                   x.value('(./ShipTo/Street2)[1]', 'VARCHAR(255)')                                             AS Street2,
                   x.value('(./ShipTo/Subdivision1)[1]', 'VARCHAR(255)')                                        AS City,
                   x.value('(./ShipTo/Subdivision2)[1]', 'VARCHAR(255)')                                        AS State,
                   x.value('(./ShipTo/PostalCode)[1]', 'VARCHAR(255)')                                          AS ZipCode,
                   x.value('(./Order/ClientOrderDate)[1]', 'DATETIME')                                          AS OrderDate
                   --x.value('(./ShippingMethods/ShippingMethod/ID)[../Selected/text()=1]','VARCHAR(255)')
            FROM   av_order CROSS APPLY orderXML.nodes('/Order/ShippingInformation') t(x)
            WHERE orderXML Is Not Null) s

This query is working fine except for the last column I am trying to select in the FROM subquery.

The difference is that column (ShippingMethod) is NOT a singleton. The XML contains all of the shipping methods and I want to select the ID of the SELECTED shipping method. Here is what that part of the XML looks like…

<Order>...
    <ShippingInformation>
        <ShipTo>
            <Name>DONT SHOW</Name>
            <Attention>DONT SHOW</Attention>
            <Street1>DONT SHOW</Street1>
            <Street2 />
            <Subdivision1>DONT SHOW</Subdivision1>
            <Subdivision2>IL</Subdivision2>
            <PostalCode>62092</PostalCode>
            <CountryCode>US</CountryCode>
            <AllowEmptyShipTo>0</AllowEmptyShipTo>
            <ContactInfo>DONT SHOW</ContactInfo>
        </ShipTo>
        <ShippingMethods>
            <ShippingMethod>
                <ID>UPSGROUND</ID>
                <Selected>1</Selected>
                <Cost>134.08</Cost>
            </ShippingMethod>
            <ShippingMethod>
                <ID>PICKUP</ID>
                <Selected>0</Selected>
                <Cost>0</Cost>
            </ShippingMethod>
            <ShippingMethod>
                <ID>UPS3DAY</ID>
                <Selected>0</Selected>
                <Cost>288.46</Cost>
            </ShippingMethod>
            <ShippingMethod>
                <ID>UPS2DAY</ID>
                <Selected>0</Selected>
                <Cost>347.91</Cost>
            </ShippingMethod>
            <ShippingMethod>
                <ID>UPSNEXTBUSDAY</ID>
                <Selected>0</Selected>
                <Cost>956.73</Cost>
            </ShippingMethod>
        </ShippingMethods>
    </ShippingInformation>
...</Order>

What do I do to select the SELECTED shipping method ID?

Seth

  • 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-09T19:40:43+00:00Added an answer on June 9, 2026 at 7:40 pm

    You can use a predicate against Selected in the xQuery expression.

    This will pick the first ShippingMethod node where Selected has the value of 1.

    x.value('(./ShippingMethods/ShippingMethod[Selected = 1]/ID)[1]','VARCHAR(255)')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to query a table with a column which is xml data with
I'm trying to write a Linq2XML query to query the following XML. I need
I'm trying to validate the following XML <query> <colors logic=AND> <color main=BLUE tone=DARK operator==
I'm trying to query a table which has a column that contains straight xml
I'm trying the following JPQL and it fails misserably: Query query = em.createQuery(SELECT u
I'm trying to query an xml column using an IN expression. I have not
I'm trying to query an xml column in sql server. I've created a primary
I'm trying to query an XML column in SQL server, and I want to
Introduction I'm trying to query an xml column in SQL server 2008, but I
I'm trying to get a result of FOR XML query as a text. I've

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.