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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:33:38+00:00 2026-06-13T15:33:38+00:00

declare @xmlsample xml = ‘<root> <solution> <solutionnumber>1</solutionnumber> <productgroup> <productcategory> <price>100</price> <title>Some product</title> <tax>1</tax> </productcategory>

  • 0
    declare @xmlsample xml =
'<root>
    <solution>
        <solutionnumber>1</solutionnumber>
            <productgroup>
                <productcategory>
                    <price>100</price>
                    <title>Some product</title>
                    <tax>1</tax>
                </productcategory>
            </productgroup>
            <productcategory2>
                    <price>200</price>
                    <title>Some other product</title>
                    <tax>2</tax>
            </productcategory2>
    </solution>
    <solution>
        <solutionnumber>2</solutionnumber>
            <productcategory2>
                    <price>200</price>
                    <title>Some other product</title>
                    <tax>2</tax>
            </productcategory2>
    </solution>
</root>'

SELECT 
    --T.C.value('(./ancestor::ns1:solutionNumber)[1]', 'varchar(50)') AS solutionnumber ?? no clue
    T.C.value('(price)[1]', 'numeric(18,2)') AS price
    ,T.C.value('(title)[1]', 'varchar(50)') AS title
    ,T.C.value('(tax)[1]', 'numeric(18,2)') AS tax
FROM @xmlsample.nodes('//node()[title]') AS T(C)

A representation of the XML I am attempting to shred in SQL Server 2008 r2. I find the “title” node and grab the values I need that are in the product category. Now I would like to get the “solution number” however this could be one or more parent nodes above the product as there are certain product “groups.”

How would I go about check the parent nodes by name (“solutionnumber”) until I find it? Thanks for any assistance.

  • 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-13T15:33:39+00:00Added an answer on June 13, 2026 at 3:33 pm

    Perhaps I was going about this backwards. Multiple cross applies will do the job. Thanks to some assistance on another forum.

    SELECT 
        --T.C.value('(./ancestor::ns1:solutionNumber)[1]', 'varchar(50)') AS solutionnumber ?? no clue
        m.c.value('(solutionnumber)[1]', 'int') as solutionnumber
        ,T.C.value('(price)[1]', 'numeric(18,2)') AS price
        ,T.C.value('(title)[1]', 'varchar(50)') AS title
        ,T.C.value('(tax)[1]', 'numeric(18,2)') AS tax
    FROM  @xmlsample.nodes ('//solution') as m (c)
    cross apply m.c.nodes ('.//node()[title]') as t(C)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

declare @x xml set @x = '<Root> <row id=1><name>Larry</name><oflw>some text</oflw></row> <row id = 2><name>moe</name></row>
Declare @xml = '&lt;root>&lt;row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada'' />&lt;row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada'' />&lt;/root>' i want to perform
DECLARE @x xml SET @x='<data> <add key=images value=image/path/img.gif>a</add> <add key=images2 value=image/path/img2.gif >b</add> <add key=images3
declare @xmlVal xml set @xmlVal = '<user> <token><id>ABC123</id><endDate>2013-06-16 18:48:50.111</endDate></token> <token><id>XYX456</id><endDate>2014-01-01 18:48:50.111</endDate></token> </user>' I need
DECLARE @SQL VARCHAR(100) DECLARE @dbName VARCHAR(100)-- SET @dbName = 'somedbname'-- SET @sql = 'USE
DECLARE @str NVARCHAR(MAX) SET @str = '<bands > <title>my bands</title> <band> <fullName>beatles</fullName> <members> <member
declare @myDoc xml set @myDoc = '<Form xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns=http://www.mydomain.org/MySchema.xsd SectionId=ABCD Description=Some stuff> <ProductDescription
DECLARE @EmployeeList varchar(100) SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + CAST(Emp_UniqueID AS
DECLARE @t TABLE(Words VARCHAR(100)) INSERT INTO @t SELECT 'Stack Overflow' UNION ALL SELECT 'EQUATORIAL'
DECLARE @imgString varchar(800) DECLARE @insertString varchar(3000) DECLARE @imgNumber int Declare @imgName varchar(100) SET @imgNumber

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.