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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:54:26+00:00 2026-05-12T17:54:26+00:00

I have something like the following XML in a column of a table: <?xml

  • 0

I have something like the following XML in a column of a table:

<?xml version="1.0" encoding="utf-8"?>
<container>
  <param name="paramA" value="valueA" />
  <param name="paramB" value="valueB" />
  ...
</container>

I am trying to get the valueB part out of the XML via TSQL

So far I am getting the right node, but now I can not figure out how to get the attribute.

select xmlCol.query('/container/param[@name="paramB"]') from LogTable

I figure I could just add /@value to the end, but then SQL tells me attributes have to be part of a node. I can find a lot of examples for selecting the child nodes attributes, but nothing on the sibling atributes (if that is the right term).

Any help would be appreciated.

  • 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-12T17:54:26+00:00Added an answer on May 12, 2026 at 5:54 pm

    Try using the .value function instead of .query:

    SELECT 
      xmlCol.value('(/container/param[@name="paramB"]/@value)[1]', 'varchar(50)') 
    FROM  
      LogTable
    

    The XPath expression could potentially return a list of nodes, therefore you need to add a [1] to that potential list to tell SQL Server to use the first of those entries (and yes – that list is 1-based – not 0-based). As second parameter, you need to specify what type the value should be converted to – just guessing here.

    Marc

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

Sidebar

Related Questions

I have something like the following <div id=container> <ul id=name_list> <li class=name> <input type=hidden
I have the following mapping: <?xml version='1.0' encoding='utf-8'?> <hibernate-mapping assembly='Core' namespace='Core.Models' xmlns='urn:nhibernate-mapping-2.2'> <class name='Basket'>
I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data
I have the following code in resultlookup.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:id=@+id/layoutResultOuter
I'm wrestling to deserialize the following XML: <?xml version=1.0 encoding=utf-8 ?> <conf name=settings> <item
I have following xml file: <table name=countries> <column name=id>1</column> <column name=name>Abkhazia</column> <column name=code>XZ</column> <column
Say I have the following table (where History is an xml column): Id Value
I have something like the following code:: <xsl:variable name=sample> <xsl:copy-of select=//foo> <xsl:copy-of select=//bar> </xsl>
I have something like the following (shown below) defined in my styles.xml file. But
I've got something like the following XML file. <credits> <property name=tag> <item>v0003</item> </property> <property

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.