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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:56:58+00:00 2026-05-24T10:56:58+00:00

I have an XML like this stored in an XML datatype column (will have

  • 0

I have an XML like this stored in an XML datatype column (will have multiple such rows in table)-

<Root xmlns="http://tempuri.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Elem1 type="T1">
    <Name type="string" display="First name">John</Name>
    <TimeZone display="Time zone">
      <DisplayName type="string" display="Display name">GMT Standard Time</DisplayName>
    </TimeZone>
  </Elem1>
</Root> 

How can I filter based on a node element say (using SQL SERVER 2008 R2) – get all ‘Elem1’ nodes or get all ‘Name’ nodes or get all TimeZone nodes ? Something like using local-name() function ?

EDIT – Part Solution –

I got the solution partly (see John’s reply below and then run this) –

SELECT C1.query('fn:local-name(.)') AS Nodes FROM [dbo].[MyXmlTable] AS MyXML CROSS APPLY MyXML.MyXmlCol.nodes('//*') AS T ( C1 ) 

The query above returns all the node elements across the TABLE. Now, I want to say filter upon specific elements and return the element and its value or its attribute value. How to achieve this (by using WHERE clause or any other filter mechanism)?

  • 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-24T10:56:59+00:00Added an answer on May 24, 2026 at 10:56 am

    I’m not sure what result you are looking for but something like this perhaps.

    declare @T table(XMLCol xml)
    insert into @T values
    ('<Root xmlns="http://tempuri.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Elem1 type="T1">
        <Name type="string" display="First name">John</Name>
        <TimeZone display="Time zone">
          <DisplayName type="string" display="Display name">GMT Standard Time</DisplayName>
        </TimeZone>
      </Elem1>
    </Root>') 
    
    declare @Node varchar(50)
    set @Node = 'Elem1'
    
    select N.query('.') as Value
    from @T as T
      cross apply T.XMLCol.nodes('//*[local-name()=sql:variable("@Node")]') as X(N)
    

    Result:

    <p1:Elem1 xmlns:p1="http://tempuri.org" type="T1">
      <p1:Name type="string" display="First name">John</p1:Name>
      <p1:TimeZone display="Time zone">
        <p1:DisplayName type="string" display="Display name">GMT Standard Time</p1:DisplayName>
      </p1:TimeZone>
    </p1:Elem1>
    

    Edit

    If you want the actual value instead of the entire XML you can do like this instead.

    declare @Node varchar(50)
    set @Node = 'TimeZone'
    
    select N.value('.', 'varchar(100)') as Value
    from @T as T
      cross apply T.XMLCol.nodes('//*[local-name()=sql:variable("@Node")]') as X(N)
    

    Result:

    Value
    ------------------
    GMT Standard Time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I have a stored proc that takes an input of xml value like this:
I have 50000 XML records like this in the database: <?xml version=1.0 encoding=UTF-8?> <root>
I have an xml file stored on my website that looks like this: <games>
I have some xml data stored in an XML Column in a table in
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>

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.