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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:21:30+00:00 2026-05-29T04:21:30+00:00

I have the following sample xml in a column of xml data type: <diagnostics

  • 0

I have the following sample xml in a column of xml data type:

 <diagnostics CurrentIterationNumber="79" TotalItemsProcessed="37847"
 ItemsProcessedLastIteration="75" ItemsProcessedPerIteration="479" />

I want to have a stored proc where I am able to pass in the name of the attribute to query. I then want to store its value into a variable to perform another set of calculations.

I have read that the .value function expects a string literal and many resources on the web advise to use the sql:variable() function for this. However, I am left with the code returning the actual contents of the variable.

Trying something along the following lines:

declare @property as varchar(50);
set @property = '@CurrentIterationNumber';

declare @x as xml;
set @x = (select PropertyValues from dbo.tblDiagnosticsSnapshot);
SELECT
    t.c.value('sql:variable("@property")', 'varchar(50)')
FROM
    @x.nodes('/diagnostics') t(c);
  • 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-29T04:21:32+00:00Added an answer on May 29, 2026 at 4:21 am

    You can use /diagnostics/@* to get a list of attributes and the compare with local-name() to get the one you want.

    declare @x xml 
    set @x = '<diagnostics CurrentIterationNumber="79" TotalItemsProcessed="37847"
     ItemsProcessedLastIteration="75" ItemsProcessedPerIteration="479" />'
    
    declare @property as varchar(50);
    set @property = 'CurrentIterationNumber';
    
    select @x.value('(/diagnostics/@*[local-name() = sql:variable("@property")])[1]', 'varchar(50)')
    

    Or like this if you expect a list of values instead of only one as in your sample XML.

    select t.c.value('.', 'varchar(50)')
    from @x.nodes('/diagnostics/@*[local-name() = sql:variable("@property")]') as t(c)
    

    Note: There should not be a @ in the search string. set @property = 'CurrentIterationNumber';

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

Sidebar

Related Questions

I have the following sample XML structure: <SavingAccounts> <SavingAccount> <ServiceOnline>yes</ServiceOnline> <ServiceViaPhone>no</ServiceViaPhone> </SavingAccount> <SavingAccount> <ServiceOnline>no</ServiceOnline>
I have the following sample code which doesn't seem to want to run. import
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have the following very simple XML file and I want to quickly parse
Suppose I have the following XML file, and I want to use PowerShell (version
I have the following XML file : <?xml version=1.0?> <Table69> </Table69> And want to
I have the following sample nested XML <?xml version=1.0 encoding=UTF-8?> <text> <main> <div n=Section
I have the following sample XML: <?xml version=1.0 encoding=utf-8 ?> <queryableData> <table displayName=Shipments dbName=Quotes>
I have the following XML sample: <finding> <title>Found something</title> <heading>Severity:</heading> <text>Really low.</text> <heading>URL:</heading> <text>https://www.something.com:443</text>
i have the following xml structure and want to add it to a treeview.

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.